Spinner Is a drop down In android software native app where you can select Item from the drop down list as per your requirement. Spinner can have scroll If list Is large and also It can have scroll If there are only few Items In drop down list. Appium software automation tool support scrollTo function to scroll at your desired Item. In this example, We will learn how to scroll down In spinner list Items of android software app and then how to select Item from spinner list using appium software automation test.
App Used For Android Spinner Test
We have to use API Demos android software app for this test and you can downloading API Demos android software app from HERE. You need to Install API Demos app In your android device.
Aim To Active In Spinner Test
We wants to scroll down In Planet spinner list and then select Item "Pluto" from the list as shown In bellow Image. Earlier we already learnt how to scroll down using scrollTo() method In THIS EXAMPLE. We will use same method here to scroll down In spinner list.
Manually you can navigate to above screen from API Demos software app -> Tap on Views -> And then tap on Spinner.
Create And Run Appium Test For Spinner
Create new test file Spinner.java under Android package of project In eclipse and write bellow given android appium test script In It.
Spinner.java
package Android;
import io.appium.java_client.android.AndroidDriver;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Spinner {
AndroidDriver driver;
@BeforeTest
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ZX1B32FFXF");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity","io.appium.android.apis.ApiDemos");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
@Test
public void selectPlanetValue() {
// Scroll till element which contains "Views" text.
driver.scrollTo("Views");
// Click on Views.
driver.findElement(By.name("Views")).click();
// Scroll till element which contains "Spinner" text.
driver.scrollTo("Spinner");
// Click on element which contains "Spinner" text.
driver.findElement(By.name("Spinner")).click();
//Find parent element of Planet drop down to uniquely Identify It's child drop down.
WebElement ele = driver.findElementById("io.appium.android.apis:id/spinner2");
//Click on Planet drop down to open drop down list.
ele.findElement(By.id("android:id/text1")).click();
// Scroll till element which contains "Pluto" text In drop down list.
driver.scrollTo("Pluto");
//Select "Pluto" from drop down list Items.
driver.findElementByName("Pluto").click();
}
@AfterTest
public void End() {
driver.quit();
}
}
Spinner Test Description
Spinner software automation test Is very simple and straight to understand If you have read my all previous android appium examples. When you run above test In eclipse,
- First It will navigate to Spinners screen.
- Then locate parent of Planet spinner.
- Using parent reference, It will locate planet spinner and click on It.
- Then It will scroll down In spinner list
- And select "Pluto" from list.
This Is the way to handle spinner In android appium test.
Hi Aravind ,
ReplyDeleteHow to identify the Toast Messages in Android Device.
Hi Aravind,
ReplyDeleteHow can we identify the Toast Messages in Android Device.
Toast messages are not supported by Appium it seems
ReplyDeleteHi,
ReplyDeleteI am having problem while selecting the value from the drop down list. I am trying the above code but it is not working.
In my Apps no spinner is used. But I am unable to find elements for list view . Can anyone please help me to find out and select the particular value from the drop down?
ReplyDeletefindElementByName is depreacted
ReplyDelete