多语言展示
当前在线:1225今日阅读:39今日分享:10

自动化测试工具Appium入门--特殊操作技巧

这里主要对一些特殊情况的处理方法进行分析。
工具/原料
1

Appium

2

Eclipse

特殊操作技巧
1

1 截屏//截屏图片保存路径static String path = 'E:\\workspace\\PhonewoTest\\ScreenshotPic\\';static AndroidDriver driver = DriverInit.driver;/*截屏* tag表示一个模块标记字符*/public static void takeScreenShot(AndroidDriver driver,String tag){     File screenShotFile =              ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);     try {      FileUtils.copyFile(screenShotFile, new File(path + tag +                  getCurrentDateTime()+ '.jpg'));     }catch (IOException e) {   e.printStackTrace();   }  }   //格式化当前时间public static String getCurrentDateTime(){   SimpleDateFormat df = new SimpleDateFormat('yyyyMMdd_HHmmss');//设置日期格式   return df.format(new Date());}

2

2 粘贴/*粘贴*/public static void Clip(WebElement el) { //获取焦点el.click();//ctrl+v的组合操作driver.sendKeyEvent(50,AndroidKeyMetastate.META_CTRL_ON);}

3

3 硬件返回driver.sendKeyEvent(4);或者,driver.sendKeyEvent(AndroidKeyCode.BACK);

4

4 滑动//向上滑动driver.swipe(20, 400, 20, 100, 300);

5

5 长按//初始化TouchAction action = new TouchAction(driver);//获取要长按的元素WebElement el = driver.findElement(By.id('cn.langma.phonewo:id/user_name'));//长按action.longPress(el).perform();

6

6 按住不放//初始化TouchAction action = new TouchAction(driver);//按住等待5秒后释放       action.press(driver.findElement(By.name('按住说话'))).waitAction(5000);action.perform();

推荐信息