Hi everyone today we will see how to use scroll action in Appium Test case.As we know in latest version of appium swipe() and scrollTo() methods are depricated lets see an alternative way to scroll through as List View.
Video Tutorial -
App Under Test -
Check out the below screenshot of the app which has ListView containing 50 rows . Each row contains Text and Toggle Button. When you click on the row text at the top you can check which row was clicked.
Test Scenario-
1. Launch Activity.
2. Scroll to List item:25.
3. Click on the row text.
4. Click on the toggle button.
Test Case -
with this post you can write test code for Vertical Scroll up to specified dimensions , Vertical Scroll till you find the element and vertical scroll till the end.
I hope you find this tutorial useful. Do share your feedback and questions in comments section below.Please follow me on social media to get latest post updates.
Video Tutorial -
App Under Test -
Check out the below screenshot of the app which has ListView containing 50 rows . Each row contains Text and Toggle Button. When you click on the row text at the top you can check which row was clicked.
Vertical Scroll |
Test Scenario-
1. Launch Activity.
2. Scroll to List item:25.
3. Click on the row text.
4. Click on the toggle button.
Vertical Scroll |
Test Case -
package com.example.anuja.appiumapplication; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.URL; import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileBy; import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.AndroidElement; import io.appium.java_client.remote.MobileCapabilityType; import static junit.framework.Assert.assertNotNull; /** * Created by Anuja on 2/8/2017. */ public class HorizontalTabScroll { AppiumDriver driver; Dimension size; @Before public void testCaseSetup()throws Exception { DesiredCapabilities cap=new DesiredCapabilities(); cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android device"); cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "4000"); cap.setCapability(MobileCapabilityType.APP, "c://apks//listviewsample.apk"); cap.setCapability("noReset", true); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap); } @Test public void testScroll()throws Exception { driver.findElementByAccessibilityId("Views").click(); AndroidElement list = (AndroidElement) driver.findElement(By.id("android:id/mobile_list")); MobileElement listGroup = list .findElement(MobileBy .AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(" + "new UiSelector().text(\" List item:25\"));")); assertNotNull(listGroup.getLocation()); listGroup.click(); } @After public void testCaseTearDown() { driver.quit(); } }
I hope you find this tutorial useful. Do share your feedback and questions in comments section below.Please follow me on social media to get latest post updates.
driver.scrollTo("List item:25") is undefined for type AndroidDriver. How do I fix it? Thank advance.
ReplyDeleteHi, check this out - http://www.qaautomated.com/2016/10/how-to-perfrom-vertical-scroll-without.html
ReplyDeletehi, I am using this method, but eclipse is saying that this method is depreciated, is there any other method round?
ReplyDeletehi,i am unable to get these 2 import can u plz guide me how to get these
ReplyDeleteimport io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
i am useing latest javaclient jar 5.0
Can i get an apk file , please?
ReplyDeleteI have textview element (Not list view item) which is not visible . It is visible only when i swipe/scroll up. I am unable to click it as it is not visible. How can i scroll up and click on that item
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteIts really helpful post. Could you please advise- how to achieve this on iOS Native App?
ReplyDeleteThanks
Hi,Can you pls provide an example to do horizontal Scroll in Appium as well without using swipe() and scrollTo()function.
ReplyDeleteHi,
ReplyDeleteUsing your code I am able to scroll to the text but unable to select the text in dropdown. No element found error is being thrown. Below is the code:
AndroidElement list = (AndroidElement) driver.findElement(By.id("coles.au.simplertools:id/locationName"));
driver.findElementById("coles.au.simplertools:id/locationName").click();
MobileElement listGroup = list.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("+ "new UiSelector().text(\"GROCERY\"));"));
assertNotNull (listGroup.getLocation());
listGroup.click();
This not working
DeleteThis comment has been removed by the author.
DeleteInstead of listGroup.click replace listGroup with the element you want to located and perform the action
DeleteHow to swipe list view and recycle view item horizontally
ReplyDeleteFrom appium version 1.6.0 and onwanrds 'scrollTo' method is depreciated by appium. You can perform scrollTo action operation using swipe method. You just need to run a 'for' loop number of times you want to scroll for the presence of Element. In each loop check the presence of Element by getting list of required element. If Element found break the loop and click.
ReplyDeleteThis works for scroll down. How would you do for scroll up to an element?
ReplyDeletePlease do write comment in your code. It would be more usefull to undersatnd.
ReplyDeleteThanks a lot. It works.
ReplyDeleteI was facing issue from so many days, now its working perfectly.
Can you plz explain how to scroll up after doing scroll down...??
ReplyDeletethanks QA-Automated
ReplyDeleteThanks a lot. It worked.
ReplyDelete