Using Selendroid For Mobile Web Test Automation

Selendroid is a test automation framework which drives off the UI of Android native and hybrid applications (apps) and the mobile web. Tests are written using the Selenium 2 client AP. In this example, you will learn how to use Selendroid for testing a mobile web application. Test site for this example is the Mahara ePortfolio demo site "".

Test case:

Admin user should be able to log on to the system.

Test Implementation

Step 1: Download the Selendroid Standalone Java libraries from this site "". If latest build is available on this location, download the latest snapshot from here "".

Step 2: Install Android SDK from the android development site "" . And setup the android development environment according to the instruction on this site "".


Step 3: Create an Android Virtual Device by using Android Virtual Device Manager after setting up android development environment.

Step 4: Start the android virtual device. Click on the start button to start the android virtual device.

Step 5: Create a Java Project, add Selendroid Standalone libraries and JUnit libraries in the build path.

Step 6: Add a JUnit test class to the project and name it "". Write the following code in this java class.

package com.seleniummaster.mobiletest;

import static org.junit.Assert.assertEquals;
import static;
import io.selendroid.SelendroidCapabilities;
import io.selendroid.SelendroidConfiguration;
import io.selendroid.SelendroidDriver;
import io.selendroid.SelendroidLauncher;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class MobileWebTest {
  private SelendroidLauncher selendroidServer = null;
  private WebDriver driver = null;

  public void ShouldLogin() throws InterruptedException {
    //clear username filed
      //enter user name
      //clear password
      //enter password
      //click on submit button
      //assert the Dashboard link text
      for (int second = 0;; second++) {
        if (second >= 60fail("timeout");
        try if (isElementPresent(By.linkText("Dashboard"))) breakcatch (Exception e) {}

      assertEquals("Dashboard", driver.findElement(By.linkText("Dashboard")).getText());
  private boolean isElementPresent(By by) {
      try {
        return true;
      catch (NoSuchElementException e) {
        return false;

  public void startSelendroidServer() throws Exception {
    if (selendroidServer != null) {
    SelendroidConfiguration config = new SelendroidConfiguration();

    selendroidServer = new SelendroidLauncher(config);

    DesiredCapabilities caps =;

    driver = new SelendroidDriver(caps);
 // Thread.sleep(50000);

  public void stopSelendroidServer() {
    if (driver != null) {
    if (selendroidServer != null) {

Step 7: Run the JUnit test.

Step 8: Check the test Result.

Below is the video of the test run.