0

I have a piece of code that works fine with java-client(5.0.0-BETA6) and selenium-java version 3.3.1. But when i upgraded to java-client version 6.1.0 and selenium-java version 3.14.0, the code started throwing errors. Need help in fixing the issue.

     AndroidDriver<AndroidElement> driver=Base.capabilities();
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
     TouchAction t=new TouchAction(driver);
     driver.findElementByXPath("//android.widget.TextView[@text='Views']").click();
     driver.findElementByXPath("//android.widget.TextView[@text='Date Widgets']").click();
     driver.findElementByAndroidUIAutomator("text(\"2. Inline\")").click();
     driver.findElementByXPath("//*[@content-desc='9']").click();

     t.press(driver.findElementByXPath("//*[@content-desc='15']")).waitAction(2000).moveTo(driver.findElementByXPath("//*[@content-desc='45']")).release().perform();

The error i am getting is:

  1. TouchAction is a raw type. References to generic type TouchAction should be parameterized"

  2. The method press(PointOption) in the type TouchAction is not applicable for the arguments (AndroidElement)

Any help in resolving this will be appreciated. Thanks.

The code that finally worked for me with new version is mentioned below. Had to make quite a few changes.

AndroidDriver<AndroidElement> driver = BaseNew.capabilities();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);    
    TouchAction t = new TouchAction(driver);
    driver.findElementByXPath("//android.widget.TextView[@text='Views']").click();
    driver.findElementByXPath("//android.widget.TextView[@text='Date Widgets']").click();
    driver.findElementByAndroidUIAutomator("text(\"2. Inline\")").click();
    driver.findElementByXPath("//*[@content-desc='9']").click();

    t.press(ElementOption.element(driver.findElementByXPath("//*[@content-desc='15']")))
            .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(3)))
            .moveTo(ElementOption.element(driver.findElementByXPath("//*[@content-desc='45']"))).release()
            .perform();
frianH
  • 7,295
  • 6
  • 20
  • 45
vaibhav misra
  • 135
  • 6
  • 19

1 Answers1

2

With Appium java_client v6.0.0-BETA1 different Options are introduced like

  1. ElementOption(to pass element)
  2. PointOption(to pass coordinates)
  3. WaitOptions(to pass wait time)

Old methods of TouchActions class are deprecated. You can see change log here

import static io.appium.java_client.touch.WaitOptions.waitOptions;
import static io.appium.java_client.touch.offset.ElementOption.element;
import static io.appium.java_client.touch.offset.PointOption.point;

  // Element Usage  
    new TouchAction(driver)
            .press(element(driver.findElementById("some_element_id")))
            .waitAction(waitOptions(ofSeconds(1)))
            .release()
            .perform();

     // Coordinate usage
        Point point =
            driver.findElementById("some_element_id_to_get_coordinate").getLocation();

    new TouchAction(driver)
            .press(point(point.x + 120, point.y + 130))
            .waitAction(waitOptions(ofSeconds(1))) // here ofSeconds is a java time Duration
            .release()
            .perform();
Amit Jain
  • 4,389
  • 2
  • 18
  • 21
  • Thanks for the input. You are right. After posting the question I searched more and found out exactly what you have mentioned. what I am wondering though is are these changes very frequent because I had to make major changes in the code to work. If they are frequent then it will make it very difficult for people to use it – vaibhav misra Sep 09 '18 at 08:22
  • In my experience it isn't something that happens frequently. – anonygoose Sep 12 '18 at 12:05