对于那些学习Appium的人来说,这是非常有用的教程,因为几乎所有移动应用程序都经常使用滑动和滚动。因此,学习使用Appium自动化将有助于您编写测试代码。以下是我编写了不同功能的代码,这些代码用于使用Appium从上至下,从下至上,从左至右,从右向左滑动。我们可以在测试用例中使用所有这些方法来执行所需的操作。另外,我还创建了带有详细说明的视频教程。
/**
/* Method to swipe screen from Bottom to Top (Vertical) Get the size of
* screen. Find swipe start and end point from screen's width and height.
* Find starty point which is at bottom side of screen. Find endy point
* which is at top side of screen. Find horizontal point where you wants to
* swipe. It is in middle of screen width.
* Time duration should be in milliseconds
*/
public void bottomTopswipe(int timeduration) {
size = driver.manage().window().getSize();
System.out.println(size);
starty = (int) (size.height * 0.50);
endy = (int) (size.height * 0.20);
startx = size.width / 2;
System.out.println("Start swipe operation");
driver.swipe(startx, starty, startx, endy, timeduration);
}
/**
*
* Method to swipe screen from Top to Bottom (Vertical) Get the size of
* screen. Find swipe start and end point from screen's width and height.
* Find starty point which is at bottom side of screen. Find endy point
* which is at top side of screen. Find horizontal point where you wants to
* swipe. It is in middle of screen width.
* Time duration should be in milliseconds
*/
public void topBottomswipe(int timeduration) {
size = driver.manage().window().getSize();
System.out.println(size);
starty = (int) (size.height * 0.50);
endy = (int) (size.height * 0.20);
startx = size.width / 2;
System.out.println("Start swipe operation");
driver.swipe(startx, endy, startx, starty, timeduration);
}
/**
*
* Method to swipe screen from right to left (Horizontal) duration should be
* in milliseconds Get the size of screen. Find swipe start and end point
* from screen's width and height. Find startx point which is at right side
* of screen. Find endx point which is at left side of screen. Find vertical
* point where you wants to swipe. It is in middle of screen height.
* Time duration should be in milliseconds
*/
public void rightLeftSwipe(int timeduration) {
size = driver.manage().window().getSize();
System.out.println(size);
startx = (int) (size.width * 0.70);
endx = (int) (size.width * 0.30);
starty = size.height / 2;
System.out.println("Start swipe operation");
driver.swipe(startx, starty, endx, starty, timeduration);
}
/**
*
* Method to swipe screen from left to right (Horizontal) duration should be
* in milliseconds Get the size of screen. Find swipe start and end point
* from screen's width and height. Find startx point which is at right side
* of screen. Find endx point which is at left side of screen. Find vertical
* point where you wants to swipe. It is in middle of screen height.
* Time duration should be in milliseconds
*/
public void leftRightSwipe(int timeduration) {
// duration should be in milliseconds
size = driver.manage().window().getSize();
System.out.println(size);
startx = (int) (size.width * 0.70);
endx = (int) (size.width * 0.30);
starty = size.height / 2;
System.out.println("Start swipe operation");
driver.swipe(endx, starty, startx, starty, timeduration);
}