Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Using Selendroid Inspect Mobile App Element Locator and Testing

When testing native mobile apps on mobile simulator/emulator/ device,identifying the element locator is very important. We can use Selendroid Inspectors to view element definition and its hierarchy.

Selendroid Inspector is a ittle web app that is embedded inside your selendroid test server. It allows you to inspect the current state of your mobile app’s UI.

Selendroid Inspector has features:
(1) View hierarchy
(2) View UI element properties
(3) UI screenshot with view locator
(4) Record the click actions
(5)Display the source html of a web view
(6) XPath helper

In this article, you will learn how to use the Selendroid Inspector to view a mobile app elements and run the test. You can find the tutorial on this site location (http://selendroid.io/inspector.html).

Important: Selenium mobile app test requires that android-sdk must be installed and configured properly on your computer, so you need to make sure that android-sdk environment was setup on your computer in advance. If you need help, please visit the site http://selendroid.io/setup.html.

Step 1: download Selendroid jar file and test mobile app.

 

navigate to Selendroid.io (http://selendroid.io) and download the two files.
selendroid-standalone-0.9.0-with-dependencies.jar
selendroid-test-app-0.9.0.apk

Step 2: Start the server

open a windows command window and run the following command. If you want to repeat the test, it is better to write a DOS batch file and add the command below, so you can start the Selendroid server by clicking on the batch file.

java -jar selendroid-standalone-0.9.0-with-dependencies.jar -aut selendroid-test-app-0.9.0.apk

Step 3: check the server status

You can check that the application(s) and the devices are recognized by opening a browser and navigating to: http://localhost:4444/wd/hub/status.

You should see a result similar to this:


Step 4: Add Jar libraries in the test project

In your Selendroid Mobile App test project, add the selendroid-standalone-0.9.0-with-dependencies.jar, and other java libraries in the build path as external jar references.

Step 5: add a JUnit test class named MobileAppTest.java and add the following code below.

package com.seleniummaster.mobiletest;
import io.selendroid.SelendroidCapabilities;
import io.selendroid.SelendroidConfiguration;
import io.selendroid.SelendroidDriver;
import io.selendroid.SelendroidLauncher;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class MobileAppTest {
  private static SelendroidLauncher selendroidServer = null;
  private static WebDriver driver = null;

  @Test
  public void testShouldBeAbleToEnterText() {
    WebElement inputField = driver.findElement(By.id("my_text_field"));
    inputField.sendKeys("Selendroid");
    Assert.assertEquals("Selendroid", inputField.getText());
  }

  @BeforeClass
  public static void startSelendroidServer() throws Exception {
    if (selendroidServer != null) {
      selendroidServer.stopSelendroid();
    }
    SelendroidConfiguration config = new SelendroidConfiguration();
    config.addSupportedApp("selendroid-test-app-0.9.0.apk");
    selendroidServer = new SelendroidLauncher(config);
    selendroidServer.lauchSelendroid();

    SelendroidCapabilities caps =
        new SelendroidCapabilities("io.selendroid.testapp:0.9.0");

    driver = new SelendroidDriver(caps);
  }

  @AfterClass
  public static void stopSelendroidServer() {
    if (driver != null) {
      driver.quit();
    }
    if (selendroidServer != null) {
      selendroidServer.stopSelendroid();
    }
  }

}

Step 6: Add break point in the test method. Basically, right click on the code line under test, and click on the "Toggle Breakpoint" item in the menu

Step 7: run the JUnit test in Debug mode. In java, you open the debug perspective and run it as debug mode.

Step 8: open a web browser and type in the Selendroid Inspector Url . In the inspector browser window, you can see the app element hierarchy and element ids. Here is the screenshot of the element id "my_text_field".

http://localhost:4444/Inspector

Step 9: continue on the next line in the debug mode. The code types in "Selendroid" in the "my_text_field" element. See the screenshot below.

Step 10: continue on the next line. The test is done and JUnit test passed.

If you have other mobile apps, you can follow the steps above to identify app elements and test its functionality.