Up and running with: Selendroid

This is the second article in our series on new, popular or otherwise interesting tools used in test automation. You can read all posts within this series by clicking here.

What is Selendroid?
Selendroid is a test automation framework for testing Android native and hybrid applications. Selendroid tests are written using the Selenium Webdriver client API, which allows for full integration with existing Selenium frameworks.

Where can I get Selendroid?
Selendroid can be downloaded from the Selendroid website.

How do I install and configure Selendroid?
Before you can start setting up Selendroid and writing tests, you need to download and install the latest Android SDK first. Clear instructions on how to do this can be found here. Make sure you also create at least one Android virtual device (AVD) and test whether it can be run properly, as we are going to need this virtual device to deploy our app under test and run our Selendroid tests on it.

NOTE: The instructions specify the creation of an AVD with the latest Android version (KitKat, API level 19). This is all wonderful, but if you’re (like me) working on a virtual machine or any other machine with limited resources, you’re probably better off creating an AVD based on Android Gingerbread (API level 10). You will need to install the correct SDK components for that API level using the Android SDK Manager. Oh, and it’s probably wise as well to use GPU emulation by enabling ‘Use host GPU’ in the AVD settings while you’re at it. This will make your test run much faster. Or, in my case, it will make your test run at all.

After you have successfully installed the Android SDK, you can install Selendroid following these instructions. When you’ve done so, start Selendroid and load the test app (the .apk file) they provide here. When you point your browser to


you’ll see something similar to this:

Selendroid is running
As you can see, Selendroid is running and it has detected our newly created AVD.

Creating a first test script
Now we’re done setting up our environment we can go to the interesting part. To start mobile testing using Selendroid, create a new Java project, add the Selendroid and Selenium .jar files as dependencies and create the following script:

public static void runSelendroidTest() throws Exception {
	// specify test capabilities (your 'test environment')
	SelendroidCapabilities capa = new SelendroidCapabilities("io.selendroid.testapp:0.9.0");
	// explicitly state that we want to run our test on an Android API level 10 device
	// explicitly state that we use an emulator (an AVD) for test execution rather than a physical device

	// start a new WebDriver
	WebDriver driver = new SelendroidDriver(capa);
	// execute a very simple test
	WebElement inputField = driver.findElement(By.id("my_text_field"));
	Assert.assertEquals("true", inputField.getAttribute("enabled"));
	Assert.assertEquals("Selendroid", inputField.getText());
	// quit testing

The comments in the code really explain it all. You can instantly see that Selendroid tests are indeed very similar to regular Selenium tests, with the exception that they are run on an app that is deployed on an AVD rather than on a website that you access using a browser.

Running your test
Running your Selendroid tests is done just like you’d run Selenium tests, so there’s really no need to go into more detail on that here.

When you run your tests, you’ll see that an Android emulator (the AVD) is started, the app is loaded, tests are executed and the emulator is closed again. Selendroid can also be used to execute tests on apps that are deployed on physical Android devices connected to your machine, something I haven’t tried myself.

A screenshot of the test app

Useful features
Selendroid offers a lot of to the tester that wants to create more useful and more complex tests. For example, you can very accurately emulate a user swipe action from right to left using the following code snippet:

WebElement pages = driver.findElement(By.id("some_id"));
TouchActions flick = new TouchActions(driver).flick(pages, -100, 0, 0);

Using the instructions presented here, just try and see for yourself what you can do with Selendroid. And of course, please share your experiences here.

Further reading
Again, the official Selendroid site can be found here. It offers a lot of information on the possibilities and features of Selendroid.

Happy mobile testing!

Up and running with: JUnit

This is the first article in a new series on tools used in test automation. Each of the articles in it will introduce a specific test tool and will show you how to get up and running with it. The focus will be on free and / or open source test tools as this allows everyone with an interest in the tool presented to get started using it right away.

What is JUnit?
JUnit is a unit testing framework for Java. Is it part of a family of unit testing frameworks for a variety of programming languages, known collectively as xUnit. With JUnit, you can quickly develop and run unit tests for Java classes to verify their correctness.

Where can I get JUnit?
JUnit can be downloaded from here. However, when you use an IDE such as Eclipse or IntelliJ, JUnit comes with the installation, making getting started with JUnit test development even easier.

How do I install and configure JUnit?
As I prefer using Eclipse, the instructions below show you how to start developing and running JUnit tests in Eclipse. Those using IntelliJ are referred to the IntelliJ homepage.

To start using JUnit to run tests on your code, all you need to do is to add the JUnit library to your existing Java project. To do this, right-click on your project, select Properties, go to the Libraries tab and press the ‘Add Library’ button. Select JUnit from the list and click ‘Next’. Then, select ‘JUnit 4’ as the library version and click ‘Finish’. JUnit has now been added to your project libraries and you’re ready to go.


Creating a first test script
Now, let’s create a first JUnit test script. First of all, as JUnit tests are Java classes in themselves, we create a new source folder in our project to prevent test code getting mixed up with application code. Right-click on your project, select Properties and in the Source tab, select ‘Add Folder’. Name this folder ‘test’ for instance and add it to your project.

It’s a good idea to structure the test code in your test folder similar to the application code to be tested. So, if the Java class you are writing tests for is in package x.y.z in the ‘src’ folder, your test code for this class is placed in package x.y.z in the ‘test’ folder. Create this package in the ‘test’ folder by right-clicking it and selecting ‘New > Package’.

One of the features of Eclipse is that it can automatically generate JUnit test skeletons for you based on the definition of the class you’re writing tests for. To do so, right-click on the package you’ll place the test code in and select ‘New > JUnit Test Case’. Name your test class – I prefer adding ‘Test’ to the name of the class to be tested, so tests for class Apple.java are placed in AppleTest.java – and select the class under test using the button ‘Select’ next to ‘Class under test:’. Click ‘Next’ and select the methods for which you want to generate JUnit tests.


Click ‘Finish’ to generate JUnit test skeletons for the selected methods. The code generated should be similar to this:

package com.ontestautomation.selenium.objectmap;

import static org.junit.Assert.*;

import org.junit.Test;

public class ObjectMapTest {

	public void testObjectMap() {
		fail("Not yet implemented");

	public void testGetLocator() {
		fail("Not yet implemented");


The annnotation @Test is used by JUnit to indicate the start of a test case. The generated test code is neatly placed in the right package in your Java project:


Running your test
To run your JUnit tests, simply right-click the test code file and select ‘Run As > JUnit Test’. Your test methods will be executed and a new tab opens displaying the test results:


Both tests fail for now as they have not yet been implemented. That is, no actual tests are being executed so far as we haven’t written the tests itself yet. Below you see a simple test for the getLocator method that tests whether the object retrieved from the object map using this method is equal to the object that is expected.

public void testGetLocator() {
	ObjectMap objMap = new ObjectMap("objectmap.properties");
	try {
		By testLocator = objMap.getLocator("bing.homepage.textbox");
		assertEquals("Check testLocator object",By.id("sb_form_q"),testLocator);
	} catch (Exception e) {
		System.out.println("Error during JUnit test execution:\n" + e.toString());

If we rerun the test code, we now see that the test for the getLocator method passes, meaning we have successfully implemented and run our first JUnit test!


Useful features
To write more advanced and better maintainable tests, JUnit provides some nice features. The most important of these features are:

  • The ability to test for expected exceptions. If you want to validate that the method you developed throws the right exception under the right circumstances, you can easily verify this with JUnit, using the expected=NameOfException.class notation:
public void testGetLocatorException() throws Exception {
	ObjectMap objMap = new ObjectMap("objectmap.properties");
	By testLocator = objMap.getLocator("unknownobject");
  • The ability to create test suites using the @Suite annotation. Using this you can run a set of test classes by calling a single test suite class.
  • The ability to parameterize tests with test data, using the @Parameterized annotation. Using this you can make your unit tests data driven and run the same tests using multiple sets of test data without the need for duplicate test code.
  • The ability to easily export test results to continuous integration frameworks, such as Jenkins. JUnit generates reports in an XML format that can easily be interpreted by Jenkins and similar CI frameworks. This results in a very readable graphical representation of your JUnit test results:


Further reading
For more information on JUnit, you can visit the sites below:

An Eclipse project including the tests I’ve demonstrated above and the reports that have been generated can be downloaded here.

Happy unit testing!