My scenario is to scroll to somewhere in the middle of the page, to an element which is dynamic. Now when I use touchAction using :-
TouchAction tc2=touchAction.press(PointOption.point(startX, startY)).waitAction().moveTo(PointOption.point(endX, endY)).release().perform();
The amount of scrolling is inconsistent, sometimes it over scrolls and sometime it underscrolls. Also we do not have a boolean return for touch action to know wheather it has actually worked or not.
Q1.How do we validate wheather or not TouchAction is working correctly or not?
Q2.Which is the best way to implement scroll for mobile devices using appium?
This is good approach I have used. You can do scrolling to look a specific element with UiAutomator2
OR scrolling till the element
is visible on page.
Add in desired capability UiAutomator2
if you are using appium
as automation engine.
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
Now use below functions if you have element's id, and index as 0 for there is one element on page.
public void scrollByID(String Id, int index) {
try {
driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().resourceId(\""+Id+"\").instance("+index+"));"));
} catch (Exception e) {
e.printStackTrace();
}
}
There is more ways to do scrolling. You can find them here