標籤:
1.首頁滑動圖片點擊
1 /** 2 * This Method for swipe Left 3 * 大距離滑動 width/6 除數越大向左滑動距離也越大。 4 * width:720 5 *height:1280 6 * @author Young 7 * @param driver2 8 * @param during 9 */10 public void swipeToLeft2(AndroidDriver driver2, int during) {11 int width = driver2.manage().window().getSize().width;12 // System.out.println("width:"+width);13 int height = driver2.manage().window().getSize().height;14 //System.out.println("height:"+height);15 //driver2.swipe(width * 3 / 4, height / 2, width / 4, height / 2, during);16 driver2.swipe(width * 8 / 9, height / 2, width / 8, height / 2, during);17 // wait for page loading18 }
使用方法:
swipeToLeft2(driver,3000);
2.儲存
/** * This Method create for take screenshot * 捕獲功能 * @author Young * @param drivername * @param filename * 調用snapshot((TakesScreenshot) driver, "zhihu_showClose.png"); */ public static void snapshot(TakesScreenshot drivername, String filename) { // this method will take screen shot ,require two parameters ,one is // driver name, another is file name String currentPath = System.getProperty("user.dir"); // get current work // folder File scrFile = drivername.getScreenshotAs(OutputType.FILE); // Now you can do whatever you need to do with it, for example copy // somewhere try { System.out.println("save snapshot path is:" + currentPath + "/" + filename); FileUtils.copyFile(scrFile, new File(currentPath + "\\" + filename)); } catch (IOException e) { System.out.println("Can‘t save screenshot"); e.printStackTrace(); } finally { System.out.println("screen shot finished, it‘s in " + currentPath + " folder"); } }
使用方法:
snapshot((TakesScreenshot) driver, "firstjt.png");
3.驗證元素是否存在
//驗證登入元素是否存在 public boolean isElementExsitAndroid(AndroidDriver driver,By elemnt){boolean flag = false; try { WebElement element=driver.findElement(elemnt); flag=null!=element; } catch (NoSuchElementException e) { System.out.println("Element:" + elemnt.toString() + " is not exsit!"); flag=false; } return flag; }
使用方法:
isElementExsitAndroid(driver,By.id("com.zhanglb.yijiebao:id/editRemark"));
4.appium初始化:
/** * android設定項目初始化 * */public AndroidDriver appConfige(AndroidDriver driver){ //設定apk的路徑 File classpathRoot = new File(System.getProperty("user.dir")); File appDir = new File(classpathRoot, "apps"); File app = new File(appDir, "debuglemonoa.apk"); //設定自動化相關參數 DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); //這句不是必須的 //啟動哪種裝置,是真機還是模擬器? capabilities.setCapability("deviceName", "Android Emulator"); //android模擬器 //使用哪種平台 capabilities.setCapability("platformName", "Android"); //設定安卓系統版本 capabilities.setCapability("platformVersion", "4.4.2"); //設定apk路徑 capabilities.setCapability("app", app.getAbsolutePath()); //設定名稱逾時時間 //capabilities.setCapability("newCommandTimeout",30); //以毫秒為單位,等待 Webview 上下文啟用的時間 //capabilities.setCapability("autoWebviewTimeout",10); //等待裝置在啟動應用後準備就緒的逾時時間。以秒為單位。 capabilities.setCapability("androidDeviceReadyTimeout",10); //行動瀏覽器名稱 Chromium Google瀏覽器 // capabilities.setBrowserName("Chromium"); //設定app的主包名和主類名 主要的參數 appActivity注意,原生app的話要在activity前加個"."。 capabilities.setCapability("appPackage", "com.zhanglb.yijiebao"); capabilities.setCapability("appActivity", "com.hzh.main.WelcomeActivity"); // capabilities.setCapability("appPackage", "com.qihoo.util"); //capabilities.setCapability("appActivity", ".StartActivity"); //初始化 //driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); //driver=new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); try {driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); } catch (MalformedURLException e) {// TODO Auto-generated catch block e.printStackTrace(); } return driver;}
appium 學習各種小功能總結--功能有《滑動圖片、儲存、驗證元素是否存在、》---新手總結(大牛勿噴,新手互相交流)