Scrolling in appium

ScrollingScreen_AppiumScrolling on mobile handsets or handheld devices can be of up or down,

Scenario: some times elements can’t be identified as those are not visible on screen, but once we scroll down to make it visible, and then can be easily identified.

Scroll is possible in both native app and also on mobile browsers, we will see one by one.

 

Scrolling on native apps:

NOTE: get the size of the device screen or size of the element on which scrolling needs to be done, so that same code can be run across difference devices.

On java-client 6.0 onwards, we have use PointOptions.point() to assign coordinates and WaitOptions.waitOptions() to assign duration

 

On java-client version 5.0 on wards, swipe() method deprecated, workaround is to use io.appium.java_client.TouchAction

 

On Java-client 4.0 version onwards, scrollTo() or scrollToExact() methods are deprecated, workaround is to use swipe() method (implemented from TouchShortcuts interface)

 

Implementation

 

DriverFactory.java

Invoke the mobile application and instantiate the driver

 

MobileDriver.java

Get and set the driver instance

 

Scrolling.Java

scrollDown() method will scroll down on screen, scrollDownTillWebView() method will scroll until required element is found.

scrollTillWebView() can be implemented in other way like, you can get whole list items into a list<WebElement> and then iterate the items, once the required item text is matching, you can stop scrolling and select the item. [try & let me know if any issues]

 

TestApp.java

Actual Test to call the scroll functionality

 

Run the below testng.xml to perform scrolling

 

Code explanation –




Above script will scroll from top to bottom till it reaches to “Web View” option and then clicks on that option.

scrollingAppium

Watch the demo here

On mobile browser:

Above method will not work for mobile browser, so we need to use as usual selenium scroll using JavaScriptExecutor.

 

For more ways to scroll on browser, follow Scrolling browser using selenium
Short link – bit.ly/qav-apmScroll

Content posted is based on learning or working experience,
Share the post with others if find useful,
Any queries?, leave comments or discuss on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *