1 screenshots
// screenshots saved path
static String path = "E:\\workspace\\PhonewoTest\\ScreenshotPic\\";
static AndroidDriver driver = DriverInit.driver;
/ * Screenshots
* Tag represents a module mark character
*/
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 ();
}
}
// format the current time
public static String getCurrentDateTime(){
SimpleDateFormat df = new SimpleDateFormat ( "yyyyMMdd_HHmmss"); // set the date format
return df.format(new Date());
}
2 Paste
/ * Paste
*/
public static void Clip(WebElement el) {
// gets focus
el.click();
// ctrl + v combined operation
driver.sendKeyEvent(50,AndroidKeyMetastate.META_CTRL_ON);
}
3 Hardware return
driver.sendKeyEvent(4);
or,
driver.sendKeyEvent(AndroidKeyCode.BACK);
4 Slide
// slip up
driver.swipe(20, 400, 20, 100, 300);
5 Press
//initialization
TouchAction action = new TouchAction(driver);
// Get the element to be pressed long
WebElement el = driver.findElement(By.id("cn.langma.phonewo:id/user_name"));
//Press
action.longPress(el).perform();
6 Press and hold
//initialization
TouchAction action = new TouchAction(driver);
// Wait 5 seconds Press and hold the release
action.press (driver.findElement (By.name ( "hold down the talk"))) waitAction (5000).;
action.perform();