Some time we need to scroll (swap ) screen to scroll application, it can be left, right up and down. You can use following function to achieve this.
Call this function in your code like below:
public void scrollFormCenter(String
direction) {
Dimension
size = driver.manage().window().getSize();
switch
(direction) {
case
"up":
int
x = size.width / 2;
int
endy = (int) (size.height * 0.75);
int
starty = (int) (size.height * 0.20);
driver.swipe(x,
starty, x, endy, 1000);
break;
case
"down":
x
= size.width / 2;
starty
= (int) (size.height * 0.75);
endy
= (int) (size.height * 0.20);
driver.swipe(x,
starty, x, endy, 1000);
break;
case
"left":
int
y = (int) size.height / 2;
int
startx= (int) (size.width * 0.15);
int
endx = (int) (size.width * 0.75);
driver.swipe(startx,
y, endx, y, 1000);
break;
case
"right":
y
= (int) size.height / 2;
endx
= (int) (size.width * 0.15);
startx
= (int) (size.width * 0.85);
driver.swipe(startx,
y, endx, y, 1000);
break;
}
}
Call this function in your code like below:
scrollFormCenter(down) //for
scrolling down
scrollFormCenter(left) //for
scrolling down
scrollFormCenter(right) //for
scrolling down
scrollFormCenter(up) //for scrolling down
Thank you for benefiting from time to focus on this kind of, I feel firmly about it.
ReplyDeleteandroid development
in this case swipe is not defined ,it showing like The method swipe(int, int, int, int, int) is undefined for the type AndroidDriver.
ReplyDelete