Getting Started with Robotium – The Most Popular Android Application UI Testing Tool

Robotium is the android Test Automation framework for testing native and hybrid android applications. It provides a simple API to write UI automation scripts. However, the number of tools are available for testing Android applications, Robotium is the most commonly used Android testing tool.

Robotium can be used to write functional, system and user acceptance test cases. Robotium Test cases can be executed in the Android emulator as well as the Android real device.

Further reading => Beginner’s Guide to Mobile Application Testing

Getting Started with Robotium

Getting Started With Robotium

Benefits Of Robotium

  • Easy to write
  • Simple API (All Methods are available only in Solo Class)
  • Automatic Delays & Timings
  • No need to write code, when navigating from one activity to another activity.
  • Test Android native apps as well as the hybrid app.
  • Able to handle multiple Android activities.
  • Less time to write tests as the API is simple.
  • Test cases are Robust, due to runtime binding to UI components
  • Fast test case execution.
  • Integrates easily with Maven and ANT.


#1) Download and Install JAVA

  • Download Java from this page.
  • Add java libraries to the PATH and set JAVA_HOME to the root of java installation directory in your environment.

#2) Download ADT Bundle

  • Download the ADT bundle from this page.
  • Extract the ADT bundle zip and put it in a folder.
  • Set ANDROID_HOME to the root of the ADT bundle folder in your Environment.

Creating A Robotium Project

Only a few steps required to create a project,

Step #1) Open Eclipse, contains your android application to be tested.

robotium tutorial-1

Step #2) Right-click on the android project -> Android Tools and click on the new Test project.

Step #3) Give a name for the Test project and click the Next button.

robotium tutorial-2

Step #4) Select The Application under test as the target and click the Finish button.

robotium tutorial-3

Step #5) Test project will be created in the eclipse workspace.

Step #6) Download Robotium solo jar from here.

Step #7) Right-click on the Test project in the workspace Go to the Build path and click Configure build path.

Step #8) Switch to libraries tab, click on the “Add External jars” option and browse the downloaded Robotium jar file and add it to the libraries and click “OK”.

robotium tutorial-4

Step #9) Robotium Test project is created successfully. Now we can create classes under the project and start writing the test cases.

Creating Robotium Class

#1) Right-click on the package under src directory in the Test project, and create a new class.

#2) Import the Main Activity class the Robotium test project.

 import com.sasi.attendanceproject.Home; 

#3) New class will inherit properties from ActivityInstrumentationTestCase2 class

public class AttendanceTest extends
ActivityInstrumentationTestCase2 <home> 

(Note: Here, Home is the activity to be tested in the Android application)

#4) Create Instance for Solo class as below

 private Solo solo; 

#5) Create a Constructor for the Test class, as below

public AttendanceTest() {
    // TODO Auto-generated constructor stub

#6) Create setUp and tearDown methods, as below
setUp method is used to Initiate the Instrumentation

public void setUp()throws Exception
   solo=new Solo(getInstrumentation(), getActivity());

Teardown method is used to close the activity after the test has been completed.

 public void tearDown() throws Exception
 { solo.finishOpenedActivities();

Some Robotium Methods

#1) assertCurrentActivity (text,Activity)
This method verifies whether the current activity is the activity that is passed as the send parameter.

solo.assertCurrentActivity("Current Activity", Home.class);

#2) clickOnButton(text)
This method will click on the button with the specified Text.


#3) clickOnButton(int)
This method will click on the button with the specified index.


#4) waitForText(text)
This method will wait until the text appearing on the activity.

solo.waitForText("Creating New Password");

#5) enterText(int, text)
This method will type the text passed as the second parameter to the specified index edit box.


#6) clickOnCheckbox(int)
This Method will click on the checkbox with the given index.


#7) clickOnRadioButton(int)
This Method will click on the Radio button with the given index.


#8) clickOnImage(int)
This Method will click on the image with the given index.


#9) clearEditText(int)
This Method will clear the text in the edit box with the given index.


#10) waitForText(text)
This Method will wait until the given text is appearing on the activity.


Example Program

Locating Elements in Android Application

Step #1) Open Eclipse containing Android Application to be Tested.

Step #2) Expand the project, Go to res? Layout folder and double click on the activity XML file, you want to automate. It will open the designed activity in the eclipse editor.

Step #3)Locating Button Element

  • Locating Element By ID

Click on the Element, you want to locate. On the right side properties panel, you can find the ID of that element. (ignore @+id/)

robotium tutorial-5

In the Above figure ID of the element is, btnadmin.

Corresponding Robotium code to locate this button is,

  • Locating Element By Position

robotium tutorial-6

In case, if the ID is not available then you can locate the element using the order. If the button is in the second position, Then you can locate the button by,

  • Locating Element By Text

robotium tutorial-7

Even you can click on the button using the text displayed on the button.

  • Locating Text box Element

Using a Similar way click on the text box you want to enter data and find the position of the text box from the right side.

robotium tutorial-8

//Username textbox is in 1st position
//Password textbox is in 2nd position 
  • Locating a Radio Button Element

Click on the Radio Button Element, you want to click and find out the position of the radio button.

robotium tutorial-9

//It will location radio button in the second position. 

Sample Code

package com.sasi.attendanceproject.test;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.EditText;

import com.robotium.solo.By;
import com.robotium.solo.Solo;
import com.robotium.solo.WebElement;
import com.sasi.attendanceproject.Home;

public class AttendanceTest extends ActivityInstrumentationTestCase2<Home>{
    private Solo solo;
    public AttendanceTest() {
        // TODO Auto-generated constructor stub

    public void setUp()throws Exception{
        solo=new Solo(getInstrumentation(),getActivity());
    public void testAttendance()throws Exception{
        //solo.assertCurrentActivity("Current Activity", Home.class);
        solo.waitForText("Creating New Password");
        solo.enterText(0, "test");
        solo.enterText(1, "test");
        solo.waitForText("Attendance Login");
        solo.enterText(0, "Anitha");
        solo.enterText(1, "test");
        solo.clickOnButton("Add New Details");
        solo.waitForText("Enter the Employee Details");
        solo.enterText(0, "Anitha");
        solo.enterText(1, "6");
        solo.enterText(2, "Testing Engineer");

    public void tearDown()throws Exception{

Executing The Robotium Project

From Eclipse:

Right-click on the project and select Run As -> Android JUnit Test

From Command Prompt:

Step #1) Cd to your Android Test Project Directory

Step #2) Run the following command,

 adb shell am instrument -w <<package name of your test

robotium tutorial-10


  • Robotium is the most commonly used Android Test automation tool.
  • Robotium Test cases can be executed on Android Emulator as well as the Real device, we don’t need to write any specific configuration code to run Robotium test cases on the Real device.
  • Robotium Can be easily written in the Maven project also, and it can be run through continuous integration tools.
  • Thus, Robotium is very useful in writing easy/simple Android Test automation scripts.

Recommended reading => 5 Mobile Testing Challenges and Solutions

About the author: This is a guest post by Anitha Eswari. She is currently working as a senior testing engineer with more than three years of extensive experience in web and mobile automation testing. She is having sound knowledge in various automation testing tools including mobile testing tools like Robotium and Appium.

In our next article, we will discuss more on Selendroid Tutorial.

Recommended Reading

31 thoughts on “Getting Started with Robotium – The Most Popular Android Application UI Testing Tool”

  1. Very nice post with a very descriptive description for any beginner.
    Thank you!!

  2. Really nice post, thanks for posting it here !!

  3. this is a perfect android automation framework. we are using it for all our user interface automation tests.

  4. excellent explain it really helps a lot.

  5. Its kick to start Mobile Automation….
    Easy to start for beginners….

    most awaited for post happy to see it…..

    thank you Anitha Eswari & Vijay.

  6. @Dwarika – Thank you!!!

    • Hi Anitha,

      iam new to mobile app testing. i need ur support in real time installation and testing the performaance of mobile app…can u please help..please leave a message at 8977168683

  7. @Kimevu – Yes, you are correct, Robotium is a perfect automation framework for automating UI tests in Android Mobiles.

  8. @Niraj – Thank you!! Keep reading my articles.

  9. @Siddhant Raut – Thank you so much, Keep reading my articles.

  10. Superb. Very good intro.

  11. Very helpful article. I have used your tutorial to be able to create a Test class that is able to test Activities for my Application, now my challenge is that i have both Activities and fragment Classes, how do i create test for that freagments ??

    please help, tell me how to go abpout it ..

  12. Hi Anitha,

    Thanks for sharing the good information about mobile automation testing.
    Can you please tell me if somebody is providing online training on core java,robotium , monkey talk and appium.
    I want to learn all these.

  13. Hi anitha, I have big doubt pls help!!! is that possible to automate the cache, performance related test cases. If it is so can u pls suggest me how to do that.

  14. Thanks for the post anita very helpful. Do you guys have any post related new google Express tool in android studio.

  15. HI Thanks for post,
    i started for my project, but project is completely based on web-services including UI and data are dynamic so to identify a dynamic UI and data. I have check layout there is no images and data. so is any other way to identify the property’s of the dynamic UI & data

  16. Any one provide training here for robotium?

  17. Any one provide training here for robotium?

  18. excellent description, really helped lot to start with Robotium test script

  19. Is this robotium will handle android OS level objects like i want to click on settings and modify the my wifi connection.

  20. awesome description about robotium, Thanks

  21. It is very much help full. Description is really good. Thank you very much.

  22. Thanks a lot for the description. I am a beginner. I would like to know what level java knowledge is required in Robotium? please do answer.

  23. “Open Eclipse containing Android Application to be Tested”
    What the hell does this mean? Can you explain? I have an app to test and how can I open it in eclipse?

  24. Good one but whats the app we are going to test here. How we have attached the app (apk – android package kit).

    Yet to give a try for the practical

  25. What if i have two emulator running, what will be the command line and how do i identify multiple emulator. I want to run the same test case for multiple emulator.

  26. hi
    thanks for the post , can u tell me how to scroll up /down or swipe option in robotium

  27. Really nice post……

  28. Hi…i want to learn about automation i really dont know much about Pre-requisities states to install java and include java libraries…did it mean eclipse..i don’t understand how this can be done..can u pls explain it

  29. Hi,
    Can we use Robotium with Android Studio?
    Is Robotium Test Recorder is free or licensed?
    If YES, then how? Can please describe the steps?
    Are the test scripts are generated automatically ot do we have to write those?


Leave a Comment