Hi Jonahss,
Thank you for the assistance!
Eventually I’ve been able to successfully execute TouchActions (swipe, tap etc…) by switching the driver to NATIVE_APP as you’ve suggested.
I now understand, that currently, appium supports Touch Actions only in native context (otherwise, I got a "Not implemented yet…error).
Unless I’m wrong, this means that if one desires to utilize the the benefits of TouchActions while testing a Mobile Web, he should get the coordinates of the WebElement he wants to manipulate via a TouchAction, switch to Native context, execute the touch command via an api that accepts X,Y coordinates and then, switch the driver back to the previous context like in the following pseudocode:
WebElement element = driver.findElement(By.id(“testElement”));
Point point = element.getLocation();
Dimension size = element.getSize();
int elementCenterX = point.getX() + Math.round(size.getWidth() / 2);
int elementCenterY = point.getY() + Math.round(size.getHeight() / 2);
String originalContext = driver.getContext();
driver.context(“NATIVE_APP”);
driver.tap(1, elementCenterX , elementCenterY , 1000);
driver.context(originalContext );
Unfortunately, I still face problems trying to utilize TouchActions for mobile-web testing purposes.
The major problem, is the difference between the X,Y reference point that is used in “NATIVE-APP” context and the one that is used in “WEBIEW”.
It looks like in “NATIVE-APP” mode, the driver regards the X,Y coordinates relatively to the physical screen in device pixels (screenXY), whilst in “WEBVIEW” mode, the driver regards the X,Y coordinates relatively to the to the top left of the fully rendered content area in the browser in CSS pixels (pageXY).
This means, that in-order to make things work, we need to somehow transform the aforementioned WebElement’s PageXY coordinate to a screenXY coordinate.
I’ve tried several approaches to solve this issue - unfortunately without success.
Approach #1(use org.openqa.selenium.internal.Locatable to get the “onScreen” coordinate):
Point onScreen = ((Locatable)element).getCoordinates().onScreen();
Result: Fails - I get an error saying that AppiumDriver doesn’t support the method: onScreen()
Approach #2 (Calculate the offset between the two reference points)
In order to do so, one of the basic things we need to do is getting the window size:
driver.manage().window().getSize();
Result: Fails -I get an error saying that AppiumDriver doesn’t support window().
Would appreciate your kind advice!
Thanks again and Best Regards,
Daniel.