Created
February 15, 2019 09:14
-
-
Save manishboricha/bc192cb7e81588b02b60c4eb3e44def2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Swipe { | |
// This method will get called in all the swipe methods because appium has depricated the swipe method in appium 1.9.1 | |
public static void swipe(int fromX,int fromY,int toX,int toY) { | |
TouchAction action = new TouchAction(driver); | |
action.press(PointOption.point(fromX,fromY)) | |
.waitAction(new WaitOptions().withDuration(Duration.ofMillis(600))) //you can change wait durations as per your requirement | |
.moveTo(PointOption.point(toX, toY)) | |
.release() | |
.perform(); | |
} | |
public void swipeDown(int pixelsToSwipe) { | |
try { | |
Point value = null; | |
value = driver.findElement(By.id("elementId")).getLocation(); | |
int x = value.x; | |
System.out.println(x); | |
int y = value.y; | |
System.out.println(y); | |
int y1 = value.y+pixelsToSwipe; | |
System.out.println(y1); | |
swipe(x,y1,x,y); | |
} catch(Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
public void swipeUp(int pixelsToSwipe) { | |
try { | |
Point value = null; | |
value = driver.findElement(By.id("elementId")).getLocation(); | |
int x = value.x; | |
int y = value.y; | |
int y1 = value.y+pixelsToSwipe; | |
swipe(x, y, x, y1); | |
} catch(Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
public void swipeRight(int pixelsToSwipe) { | |
try { | |
Point value = null; | |
value = driver.findElement(By.id("elementId")).getLocation(); | |
int x = value.x; | |
int y = value.y; | |
int x1 = value.x+pixelsToSwipe; | |
swipe(x, y, x1, y); | |
} catch(Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
public void swipeLeft(int pixelsToSwipe) { | |
try { | |
Point value = null; | |
value = driver.findElement(By.id("elementId")).getLocation(); | |
int x = value.x; | |
int y = value.y; | |
int x1 = value.x-pixelsToSwipe; | |
swipe(x, y, x1, y); | |
} catch(Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
//This will help you from one element to another element | |
public void swipeFromTo(int pixelsToSwipe) { | |
try { | |
Point from = null; | |
Point to = null; | |
from = driver.findElement(By.id("elementId")).getLocation(); | |
to = driver.findElement(By.id("elementId")).getLocation(); | |
int x = fromElement.x; | |
int y = fromElement.y; | |
int x1 = toElement.x; | |
int y1 = toElement.y; | |
swipe(x, y, x1, y1); | |
} catch(Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment