-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwipeDemo.java
More file actions
44 lines (31 loc) · 1.83 KB
/
Copy pathSwipeDemo.java
File metadata and controls
44 lines (31 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import static java.time.Duration.ofSeconds;
import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import static io.appium.java_client.touch.LongPressOptions.longPressOptions;
import static io.appium.java_client.touch.offset.ElementOption.element;
public class SwipeDemo extends Base {
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
AndroidDriver<AndroidElement> driver = capabilities();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
driver.findElementByXPath("//android.widget.TextView[@text='Views']").click();
driver.findElementByXPath("//android.widget.TextView[@text='Date Widgets']").click();
// driver.findElementByXPath("//android.widget.TextView[@text='2. Inline']").click();
driver.findElementByAndroidUIAutomator("text(\"2. Inline\")").click();
driver.findElementByXPath("*//*[@content-desc='9']").click();
System.out.println("Pass");
//for swiping action
TouchAction t = new TouchAction(driver);
//long press //find Element //2sec //move to another element and release it
//t.longPress(longPressOptions().withElement(element(pn)).withDuration(ofSeconds(2))).release().perform(); //
//for performing the gesture, we have to import webelement, gesture(long press,tap option),duration packages.
WebElement first=driver.findElementByXPath("*//*[@content-desc='15']");
WebElement second=driver.findElementByXPath("*//*[@content-desc='45']");
t.longPress(longPressOptions().withElement(element(first)).withDuration(ofSeconds(2))).moveTo(element(second)).release().perform();
System.out.println("Swipe Performed");
}
}