/**
* 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();
}
}
* 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();
}
}
本文介绍了如何使用Appium进行屏幕滑动(向上滑动和向右滑动)和截图操作。提供了`swipeToUp`、`swipeToRight`方法用于屏幕滑动,以及`snapshot`方法用于截取并保存当前屏幕快照。
1536

被折叠的 条评论
为什么被折叠?



