您的位置:首页 > 移动开发

Appium滑动和截屏方法封装

2016-07-25 18:33 399 查看
/**

* Swipe up on the screen

*/

public static void swipeToUp(AndroidDriver driver, int time) {

int width = driver.manage().window().getSize().width;

int height = driver.manage().window().getSize().height;

driver.swipe(width / 2, height * 3 / 4, width / 2, height / 4, time);

}

/**

* Swipe to right on the screen

*/

public static void swipeToRight(AndroidDriver driver, int time) {

int width = driver.manage().window().getSize().width;

int height = driver.manage().window().getSize().height;

driver.swipe(width / 4, height / 2, width * 3 / 4, height / 2, time);

}

/**

* This method is created for taking screenshot

*/

public static void snapshot(TakesScreenshot drivername, String filename) {

String currentPath = System.getProperty("user.dir");

File scrFile = drivername.getScreenshotAs(OutputType.FILE);

try {

System.out.println("Saved snapshot's path is:" + currentPath + "/"

+ filename);

FileUtils.copyFile(scrFile, new File(currentPath + "/" + filename));

} catch (IOException e) {

System.out.println("Can't save screenshot!");

e.printStackTrace();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: