Appium : Select Check-box Of Android App

Check box is another common element of any native, hybrid or mobile software web applications. Selecting check box of android software app in appium test is very easy task and I hope, most of you already knows how to select android app's check box in appium automation test but i have to think about bottom level learner who don't know how to select android app's check box in appium automation software test. Let's take very simple example to learn how to select check box in appium. We can use click() method to select check box.
Do you wants to learn all appium tutorials? View this LINK.

App To Use And Aim To Achieve In Software Test 
We will use same API Demos software app of android to learn how to select check box of android app as shown in bellow image.

appium automation - select checkbox

Manually you can navigate to above screen from API Demos app's Home -> Views -> Controls -> 2. Dark Theme.

Create And Run Test
Create bellow given test in eclipse and run it using testng and appium. Observe test execution in android device.
package Android;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class SelectingCheckBox {
 AndroidDriver driver;

 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", "");
  driver = new AndroidDriver(new URL(""), capabilities);
  driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

 public void select() throws InterruptedException {
  // Scroll till element which contains "Views" text If It Is not visible on screen.
  // Click on Views.
  // Scroll till element which contains "Controls" text If It Is not visible on screen.
  // Click on Controls.
  // Scroll till element which contains "2. Dark Theme" text If It Is not visible on screen.
  driver.scrollTo("2. Dark Theme");
  // Click on 2. Dark Theme.
  driver.findElement("2. Dark Theme")).click();
  // Click on check-box to select it.
  driver.findElement("Checkbox 2")).click();

 public void End() {

Last syntax in @Test method will select the check box using .click() method when you run software test.

1 comment: