Using Selendroid to Automate the User Interactions Over a Mobile App (Part 2)

How to use Selendroid framework to automate the user interactions over a mobile application (Part-2). Also, read our ‘Selendroid Introduction Part 1‘ tutorial.

Selendroid is an amazing testing tool, which has several important features as well.

It is a very powerful automation test framework tool which can interact with multiple devices simultaneously. An application can be tested without any modification or change using Selendroid.

In this tutorial, let us see, how to use the Selendroid framework to automate the user interactions over a mobile application (.apk files).

The app under test is a recipe app, which a user can access to view, rate and perform other things. We can run this app both online as well as offline.

Expectation from the script

  • Start the server, install the apk file (if not installed previously)
  • Launch the application
  • Access the menu list and navigate to a particular category
  • Perform the advanced search to filter out the recipe within the category
  • Add review comment to the recipe
  • Verify the added review comment
  • View list of all recipe created by the author of the current recipe

Application Setup

We need to create a user over BigOven app as which would be required while adding ratings. The user credentials will be useful while we Login to the step of automating the script.

To start with:

1) Make sure that the Selendroid server is started using the following command.
E.g. java –jar selendroid-standalone-0.15.0-with-dependencies.jar –aut 250000RecipesBigOven.apk
Note: 250000RecipesBigOven.apk is the application under test.

2) Make sure whether the physical device is connected to the PC and any test environment with USB debugging mode is enabled.

3) Make sure that the required Selendroid, selenium jar files are already imported and attached to the libraries.

The first step would be creating new  Package

Mentioning the package name

Next step would be creating a TestNG test case under the above package.

Creating new TestNG Class

1) Open the eclipse project
2) Right-click on the package name. Here it is SelendroidFirst
3) Click on TestNG >> create TestNG class

Specifying the Class Name say ‘BigOven’

Selendroid Script

Now paste the following codes over the newly created class ‘BigOven’:

package SelendroidFirst;

import io.selendroid.client.SelendroidDriver;
import io.selendroid.client.TouchAction;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;

import io.selendroid.common.SelendroidCapabilities;
import io.selendroid.common.device.DeviceTargetPlatform;
import io.selendroid.standalone.SelendroidConfiguration;
import io.selendroid.standalone.SelendroidLauncher;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.List;

public class BigOven{
 public SelendroidLauncher selendroidServer = null;
 public static WebDriver driver = null;
 @Test(groups= {"Example"})
 public  void BigOven() throws Exception

SelendroidConfiguration config = new SelendroidConfiguration();config.addSupportedApp
SelendroidLauncher selendroidServer = new SelendroidLauncher(config);
SelendroidCapabilities caps = new SelendroidCapabilities();
WebDriver driver = new SelendroidDriver(caps) ;

//**Access Recipe list of particular category**//
List<WebElement> kg1=driver.findElement("kitchen_grid")).findElements("grid_item_layout"));
for(WebElement kg2:kg1)
if(kg2.findElement("bottom_text")).getText().equals("Browse By Category"))
List<WebElement> kg4 = driver.findElement("select_dialog_listview")).findElements("text1"));
for(WebElement kg3:kg4)

//**Viewing Recipe Details page**//
List<WebElement> bs = driver.findElement("layout_search_by_ingredients")).findElement

//**Adding Rating Review to a particular recipe**//
List<WebElement> bl = driver.findElement(By.className("android.widget.ListView")).findElements
for(WebElement bi : bl)
driver.findElement("review_comment")).sendKeys("Review Comment added by testuser");
List<WebElement> rl = driver.findElements("review_info"));
List<WebElement> rc = driver.findElements("reviewer_comment"));
WebElement rle = rl.get(0);
WebElement rce = rc.get(0);
if(rle.getText().contains("Testuser12345")&& rce.getText().equals("Review Comment added by testuser"))
System.out.println("Review added successfully");

//**Viewing all the recipes added by the user**//
String AuthorName = driver.findElement("recipe_author_name")).getText();
System.out.println("List of recipe created by Author: " + AuthorName);
public void afterClass() {

Once we have written the test script, the next step to Run the Script.

Select the test case >> right-click >> Run As >> TestNG Test.

Here are few snapshots of the application

Landing page:

Category list page:

Search refine page:

Viewing the Detail recipe:

Login over BigOven:

Adding Review Comments:

Viewing the added comment:

Now once the test script is executed successfully, the next step would be viewing the execution result. In TestNG, we can do the same from the console “Results of running class BigOven”.

Viewing Console Result

We can see the test results from the following default location, In our case it is SelendroidFirst >> test-output >> index.html

This is how we can execute the test cases.

We can also create testing XML file and then execute it and also enhance the test result by using TestNG reporting utility.


Selendroid is an open-source framework which allows us to create automation test cases for mobile applications.

The best thing is, it supports Hotplugging. It supports automation of several user interactions over mobile devices.

But the development work and online support are almost stopped, so we might not get all the features instantly. Hence we may face some problem while performing few actions like swap. At times we have to create our own function as well.

This is the end of the Selendroid tutorial series. Please share your comments, questions, and thoughts below.

Recommended Reading

Last Updated: April 16, 2020 1:28 pm