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 粘贴
/*粘贴
*/
public static void Clip(WebElement el) {
//获取焦点
el.click();
//ctrl+v的组合操作
driver.sendKeyEvent(50,AndroidKeyMetastate.META_CTRL_ON);
}
3 硬件返回
driver.sendKeyEvent(4);
或者,
driver.sendKeyEvent(AndroidKeyCode.BACK);
4 滑动
//向上滑动
driver.swipe(20, 400, 20, 100, 300);
5 长按
//初始化
TouchAction action = new TouchAction(driver);
//获取要长按的元素
WebElement el = driver.findElement(By.id("cn.langma.phonewo:id/user_name"));
//长按
action.longPress(el).perform();
6 按住不放
//初始化
TouchAction action = new TouchAction(driver);
//按住等待5秒后释放
action.press(driver.findElement(By.name("按住说话"))).waitAction(5000);
action.perform();