Appium tap(int x, int y) function seems to be deprecated. Any replacements?

Sandeep Harisankar :

I'm trying to automate an Android game and for that I'm using X,Y co-ordinates to make a button click, as identifying elements through ID, Xpath etc. is not possible for games. I'm using TouchAction tap(int x, int y) method (Appium Method) for achieving this. But unfortunately this method tap(int x, int y) seems to be deprecated. The other options replacing this looks to be --> touchAction.tap(PointOptions tapOptions) and touchAction.tap(TapOptions tapOptions). The same is the case with touchAction.press as well.

My code to touch a specific button looks like this:

TouchAction touchAction = new TouchAction(driver);
touchAction.tap(1280, 1013).perform();

Here, the X,Y values are found using Touch points in Android Device [Developer Options > Show pointer location]

Can anyone suggest a better way to achieve the same using non deprecated method? Thanks!

Taryn :

You can view the TouchAction documentation here:

https://appium.github.io/java-client/io/appium/java_client/TouchAction.html

Here's the method that replaced the tap() you are using:

https://appium.github.io/java-client/io/appium/java_client/TouchAction.html#tap-io.appium.java_client.touch.offset.PointOption-

and here is the PointOption documentation, which is the new parameter to use with tap():

https://appium.github.io/java-client/io/appium/java_client/touch/offset/PointOption.html

So to answer your question, you have two choices with PointOption:

  1. Using PointOption.point(x, y), which is a static instance of PointOption with those coordinate values

TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(1280, 1013)).perform()

  1. Using PointOption().withCoordinates(x, y), which returns a reference to the PointOption instance after setting those coordinate values

TouchAction touchAction = new TouchAction(driver);
touchAction.tap(new PointOption().withCoordinates(1280, 1013)).perform()

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=474038&siteId=1