My favorites | Sign in
Project Home Downloads Wiki Issues
Search
for
Getting_Started  
Start using Robotium
Featured
Updated Jun 18, 2014 by renasr...@gmail.com

Getting started

Follow the instructions below if you want to see how Robotium works and how an Android test project looks like. If you want to create a new test project then please go to the step-by-step tutorials page.

To use Robotium, you need to add the Robotium jar to the build path of your test project. In Eclipse that is done by right clicking on the test project --> Properties --> Java Build Path --> Add (external) Jar.

Example test project

In the Downloads section you will find ExampleTestProject_v5.2.1.zip which includes a sample application and an example test project.

In Eclipse, import ExampleTestProject_v5.2.1.zip by clicking on File --> Import --> Existing Project into workspace --> Select archive file --> ExampleTestProject_v5.2.1.zip.

Then you can run these test cases either on the emulator or on device. You right click the test project and select Run As --> Run As Android JUnit Test. Example of a test case (test case spanning over multiple activities where EditorActivity is the first activity):

 
public class EditorTest extends
		ActivityInstrumentationTestCase2<EditorActivity> {

  private Solo solo;

  public EditorTest() {
		super(EditorActivity.class);
  }

  public void setUp() throws Exception {
  	solo = new Solo(getInstrumentation(), getActivity());
  }
  
  public void testPreferenceIsSaved() throws Exception {
  
  	        solo.sendKey(Solo.MENU);
		solo.clickOnText("More");
		solo.clickOnText("Preferences");
		solo.clickOnText("Edit File Extensions");
		Assert.assertTrue(solo.searchText("rtf"));
		
		solo.clickOnText("txt");
		solo.clearEditText(2);
		solo.enterText(2, "robotium");
		solo.clickOnButton("Save");
		solo.goBack();
		solo.clickOnText("Edit File Extensions");
		Assert.assertTrue(solo.searchText("application/robotium"));
		
  }

   @Override
   public void tearDown() throws Exception {
	solo.finishOpenedActivities();
  }
}
Comment by rajnaray...@gmail.com, Jan 29, 2010

Dear Sir,

I want to know about where should i import robotium-solo.jar file and the addition code "ctivityInstrumentationTestCase2".

please send the whole procedure with a very small example.

Thank You, Rajnarayan Kumar Email Id:rajnarayan.kumar@halosys.com

Comment by project member renasr...@gmail.com, Feb 2, 2010

I have updated the Getting_Started page with further instructions on how to do. I have also uploaded an example project that you can look at. The robotium-solo.jar should be added the test projects build path. Please have a look at ExampleTestProject?.zip.

Comment by ddong0...@gmail.com, Feb 20, 2010

How to import the robotium-solo.jar to the mobile software 's image ? could you mind to give me some tips ?

Comment by project member renasr...@gmail.com, Feb 22, 2010

I am not sure what you mean. Please further explain your question in our developer group:

http://groups.google.com/group/robotium-developers

Comment by seenu...@gmail.com, Feb 24, 2010

hai i cannot understand this project test. can u explain me

Comment by project member renasr...@gmail.com, Feb 24, 2010

The example test project is only a simple test project developed to show how Robotium can be used. To give you an idea of what you can do with Robotium and how you can use it to test other Android applications. If you have any specific questions please ask them in our developer group:

http://groups.google.com/group/robotium-developers

Comment by Rohit.Ka...@gmail.com, Apr 26, 2010

@ ddong0524: Just put the robotium jar file into ur android SDK's tools/lib folder and you are ready to go!, you can place it in a custom build location if required also.

Comment by tom.plun...@gmail.com, Apr 27, 2010

This is a good example of getting started with the unit tests, thanks.

Running the tests that are on the samples left me with errors that I don't understand. Looking at this code, now I understand the errors (like on ApiDemos?), but I'm still not sure how to fix them. Will figure it out, though.

Thanks for putting this together, it's very helpful. I did find that building the tests for 2.1 against a notepad for 1.5 failed two of the three tests. Rebuilding the tests for 1.6 made the tests pass. I can't seem to get the tests to build under 1.5, the resources don't seem to be properly supported.

Comment by flyingan...@gmail.com, Jun 23, 2010

I have learned more from this example for android automation testing, thanks a lot. But I have two questions about it: 1.With robotium, could I write a agent pushed into android phone, and write a client in PC to control the testing? Of course, the test cases will be written in client. 2.The example open the notepad application directly not from UI, how could I open it from UI? Hope for your reply and suggestions! Thanks

Comment by project member renasr...@gmail.com, Jun 23, 2010

Please ask your questions in our developer group:

http://groups.google.com/group/robotium-developers

Comment by scott.sr...@gmail.com, Aug 10, 2010

Thank you for your work on Robotium. It has simplified my testing considerably.

Comment by project member renasr...@gmail.com, Aug 25, 2010

I am glad to hear that. I hope you will enjoy the new release.

Comment by felipetg...@gmail.com, Aug 31, 2010

After suffering hard times... I discovered that the following tag MUST be defined in the AndroidManifest?.xml:

<uses-sdk android:targetSdkVersion="YOUR_VERSION" />

Where YOUR_VERSION, in my case, is 7. Without that, button clicks (as such as menu item clicks) does not work. The error occurs specifically at:

Class: Clicker.clickOnScreen(View view, boolean longClick) 1.7.0? Call: View.getLocationOnScreen(int xy)

The returned position gets wrong.

Please, add this clue to the "Getting_Started" wiki.

Comment by project member renasr...@gmail.com, Sep 1, 2010

Thanks for pointing this out. I will add it to the Getting Started page.

Comment by ovido...@gmail.com, Sep 2, 2010

I get the No tests found when I ran the project using Android JUnit3. everything work(start emulator, installing the app) but it stops with this error. please help! thanks.

Comment by anukul.s...@gmail.com, Sep 11, 2010

Hi Renas,

Nice work on this development. I was looking out for a tool that automates my Android application. However, there is a problem. I have built my test automation framework which is written in ruby language. I tried to use gem rjb (ruby java bridge) to interact with the JAVA api's written for Solo. Tried the following code in ruby to import the Solo class:

require 'rjb'

c = "c:/robotium/robotium-solo-1.7.1.jar;c:/robotium/robotium-solo-1.7.1-javadoc.jar" Rjb::load(classpath = c, jvmargs=) @rapi = Rjb::import('com.jayway.android.robotium.solo.Solo') puts "robotium_class=#{@rapi.inspect}"

But I get the error on running this as:

>ruby test_robotium.rb test_robotium.rb:11:in `import': android/view/View (NoClassDefFoundError?)

from test_robotium.rb:11
>Exit code: 1

Is there any other jar file which needs to be included in order to make this work via ruby, since I understand that there is no direct ruby gem for robotium as of now? Any help would be appreciated in this regard, my constraint is that I need to use your API's via ruby, because my framework is developed in that language.

Thanks, Anukul

Comment by project member renasr...@gmail.com, Sep 13, 2010

Hi Anukul,

Nice to hear that you like it. You need to also add the android.jar that is located in the Android SDK. Please tell me how this work goes. Sounds very interesting.

/Renas

Comment by ikthian...@gmail.com, Sep 16, 2010

hi renas,

thank you for your hard work behind robotium, i personally really like it. unfortunately i am facing a problem of not getting robotium to work with 1.6. it works fine with 2.2. could you kindly confirm it really works with 1.6? if it does, what extra measurements do i have to take to get it working with 1.6?

Comment by project member renasr...@gmail.com, Sep 18, 2010

Hi,

Nice to hear that you like it. Please have a look at the below part of the questions and answers page:

http://code.google.com/p/robotium/wiki/QuestionsAndAnswers

/Renas

Comment by chocolat...@gmail.com, Sep 29, 2010

Hi,

I am trying to explore robotium. And on the first attempt i tried to use the test project. I have only jre 1.6 on my machine and when i built the project i got errors saying: "annotations are only available if source level is 1.5" which is because of the @smoke annotation.

Can any one suggest do we definitely require jre1.5 along with jre 1.6?

Comment by project member renasr...@gmail.com, Oct 2, 2010

Hi,

You have to install the Android SDK. That annotation is included in: android.test.suitebuilder.annotation.Smoke

/Renas

Comment by glenview...@gmail.com, Oct 3, 2010

I have some one-time time-consuming setup code that configures my application for testing by loading a test-fixture database. I wanted to use the @beforeclass annotation (see http://junit.sourceforge.net/doc/faq/faq.htm#organize_3), but it appears Robotium may not support this. I tried importing import org.junit.Test, but the project couldn't resolve the import. Any help would be appreciated!

Comment by glenview...@gmail.com, Oct 4, 2010

Why isn't there a solo.clickLongOnButton() method?

Comment by glenview...@gmail.com, Oct 4, 2010

The answer to my previous comment re: @beforeclass is that first, it's spelled @BeforeClass?. Second, I had to fix project properties and add JUnit 4 to the library list (Eclipse offered to do this in the fix-problems dialog on the error at the line where I tried to import org.junit.Test. Lastly I had to import org.junit.BeforeClass?.

Comment by d.strick...@gmail.com, Oct 15, 2010

Hi Renas,

I apologize if this is explained elsewhere, but in the sample code that you give above why haven't you called your parents setUp()? Is this intentional?

It seems that a few fields get set in the parents setUp call.

Cheers!

Comment by usman....@gmail.com, Oct 20, 2010

Hi All,

It will be good if the Application and test Application both are providing here. It could help anybody to understand it.

After looking around for 3 hrs. I was able to run the Test Application.

Thanks a lot. Usman

Comment by usman....@gmail.com, Oct 20, 2010

Plz go through to this link also.

http://wiebe-elsinga.com/blog/?p=300

Usman

Comment by gunnar0...@gmail.com, Nov 16, 2010

In my case Eclipse complains about a missing project NotesList? required by the ExampleTestProject? project installation ?

Comment by Er.Anura...@gmail.com, Nov 29, 2010

I am targeting facebook as my base application and writing an app using Robotium framework.

I could successfully implemented few features and stuck at one point very badly. I want to automate upload picture functionality but as soon as upload button click happened device default application gets activated and i couldn't control the default app using robotium.

Is there any way by which i can overcome this impediment by writing some code using robotium or writing a layer between OS & Robotim which can generate key stokes.

Quick help would be much much appreciated.

Thanks

Comment by project member renasr...@gmail.com, Dec 1, 2010

In your test project you define which target package you want to test. The default application that gets activated does not have that package name. Therefore you are not allowed to use Robotium on it. You could resign it and create a new test project for it. Please see the wiki pages.

/Renas

Comment by doctor.m...@gmail.com, Jan 7, 2011

When I import the test project example, I have a loop in building the workspace. What kind of sdk I have to use?

Comment by project member renasr...@gmail.com, Jan 7, 2011

You have to install the Android SDK. Please see:

http://developer.android.com/sdk/index.html

/Renas

Comment by doctor.m...@gmail.com, Jan 8, 2011

I have already installed the Android SDK. When I created the Notpad project, I used the Andorid SDK 1.6 or higher. Anyway, importing the test project example, eclipse starts to build the workspace, but never ends.

Comment by doctor.m...@gmail.com, Jan 10, 2011

I need something similar to IBM Functional Tester for Android app. Can Robotium do that?

Comment by lukap...@gmail.com, Jan 10, 2011

I'm trying to following the user guide to create a new test project where I have the source code, but the linked guide is unavailable, any idea? Thanks!

Comment by project member renasr...@gmail.com, Jan 10, 2011

The guide is up again now.

/Renas

Comment by www.guos...@126.com, Jan 18, 2011

Hi,

This is a good example of getting started with the unit tests, thanks.
but when i try to test calculator,i find so many problem in my program.i write some testcase to test the calculator,for example,test0,test1,test2.......test0 is for plus,it is ok.test1 i want to test sin0,but it could not complete,it shows :something is in the way,could not click the button "sin",even if i insert solo.sleep(1000),it is of no effect.
Thank you!Quick help would be much much appreciated.

Comment by project member renasr...@gmail.com, Jan 20, 2011

Please have a look at: "Why do text and button clicks get wrong?" http://code.google.com/p/robotium/wiki/QuestionsAndAnswers

/Renas

Comment by RicJH...@gmail.com, Feb 1, 2011

In Eclipse click on File --> New --> Project --> Android Project --> Create Project from existing source --> NotePad?. I named the project XX

After importing ExampleTestProject?_v2.1.zip I needed to open the NotePadTest? project. Go to the Properties > Projects and add the project XX (which I just created) to the build bath.

Also checked the "Order and Export" checkbox for robotium-solo-2.1.jar and project XX

I then had to make sure that

Comment by phanindr...@gmail.com, Feb 10, 2011

Hi Renas,

we are having issues with identifying the objects. Please let us know the process to identify objects if .apk file is provided

Comment by project member renasr...@gmail.com, Mar 1, 2011

The example project is developed using Eclipse. Robotium works with all the different IDEs. You only need to add the robotium jar to the build path of your test project.

Comment by priyakot...@gmail.com, Mar 10, 2011

HI, I had entered a question but seems like it was deleted? Strange. I am unable to click the login button. I see username/password are getting entered but clickOnButton or clickOnText or clickOnView does not work.

Comment by project member renasr...@gmail.com, Mar 16, 2011

Please have a look at: "Why do text and button clicks get wrong?" http://code.google.com/p/robotium/wiki/QuestionsAndAnswers

/Renas

Comment by cktcdt...@gmail.com, May 26, 2011

Hi,Renasr, I am very glad to find this tool for Android. Thanks a lot. I want to test the drag action from a screen position to other positions, more than 2 steps. Just like the Android screen locker.

Will you please give me some advice? How to use the drag(float fromX, float toX, float fromY, float toY, int stepCount) API in this case?

Thanks a lot.

Felix

Comment by cktcdt...@gmail.com, May 26, 2011

Hi, Renasr, Another question, if I do not use solo.enterText(0, "10") to input a text, how can I use keyboard to input number or text?

Best regards Felix

Comment by wanjing...@126.com, May 30, 2011
I hava a problem that how to use bototium to open en url.

i try the below: Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.google.com")); startActivity(browserIntent);

but in the test application,"startActivity" can not be resolved.So please tell me how can i do

Thanks!

Comment by umair.as...@gmail.com, Sep 15, 2011

I followed the instructions carefully, however, I get error message saying "NotesList? is not configured correctly for running tests. See console for details.

Comment by slott.ha...@gmail.com, Sep 26, 2011

I have a working unit test project and have added a new test extending ActivityInstrumentationTestCase2? however this test case is never picked up when the test suite is executed - why is this ? I'm using the latest 2.5 and I have high hopes for this as I really like Selenium.

Comment by chenyh2...@gmail.com, Sep 29, 2011

Hello,Renasr.Nice to meet you.I am working on the Android automatic testing,I hear that robotium is a simple tool for test Android apps ,so I learn it,but now I come across a trouble.I don't know how to use robotium to test a apk without source code.when I write a constructor ,I don't know how to change it; example: public class xxx extends ActivityInstrumentationTestCase2? {

public xxx (){
super("com.example.android.notepad",NotesList?.class);
}
} I don't konw the apk package name and the enter class,how could I change it?

Comment by Philip.S...@gmail.com, Sep 29, 2011

For everyone getting SecurityExceptions? on Touch/Click events: do not call "super.tearDown();", since I removed this call I no longer get permission denied for inject events

Comment by jacob.sj...@gmail.com, Feb 1, 2012

Hi , Which one is better robotium or selenium web driver ?

Comment by ctad...@gmail.com, Feb 4, 2012

I am using Robotium for the first time. I am facing this problem related to Build path entry is missing: NotesList?.

How can I resolve this?

thanks C

Comment by niejunho...@gmail.com, Feb 7, 2012

How to test webview? My project is mainly organized by webview include input text

Comment by abhijit...@gmail.com, Feb 8, 2012

Hi, I am using Robotium for the first time I am getting a syntax error when I put "import. com.jayway.android.robotium.solo.Solo;" line the error is "The import com.jayway can not be resolved" Can anyone help me with this?

Thank you.

Comment by raafat.h...@gmail.com, Feb 10, 2012

I'm trying to follow the steps to run the example test project and I get the same error as the one the other user on Feb 4th:

I am using Robotium for the first time. I am facing this problem related to Build path entry is missing: NotesList??.

How can I resolve this?

thanks

Comment by raafat.h...@gmail.com, Feb 13, 2012

I found the cause: The Project's build path had the "required project" name set to NotesList? while the target project name is actually NotePad? (or whatever you called your NotePad? project when you created it). So just right click on the test project and select "Properties" then select "Java Build Path" and click the "Projects" tab and fix the problem (remove the NotesList? item and add the right project name)

Comment by ddeepak...@gmail.com, Feb 14, 2012

Hi,

My requirement is to create a test application which runs on a device without attaching a desktop system and gives back the resultant log file in its sdcard. Is it possible to use robotium in this case ? Does robotium requires a desktop with exclipse or other IDE to run the test app ?

Comment by project member renasr...@gmail.com, Feb 16, 2012

@ddeepakrao, With the development tools application you can run your test cases directly from device.

Comment by j_so...@sbcglobal.net, Feb 29, 2012

I got this working by the following steps:

1. Use the Notepad sample from android rev 2.3.3 (3.0 and up doesn't support menu buttons)

2. Change Properties > Projects from Notelist to Notepad if needed (as noted above)

3. Comment out the two goBackToActivity calls (it's better to test like a user anyway)

4. Add clickOnMenuItem("Save") calls after entering text for each addNote (goBack call optional)

5. Update SDK and restart if it complains about no default.properties, the test code uses the newer project.properties. (If you refuse to upgrade, unzip the test project and rename the properies file before importing)

Comment by grnd...@gmail.com, Mar 29, 2012

Excellent, I was able to figure out how to setup my activity and even though I have a custom application class, I was able to set it up using the setUp() with getActivity().getApplication() and initialize all the parameters needed for my Activity. Once I did that the Solo calls worked like a charm and my robot user was clicking around in the activity. Thanks for making this, it makes unit testing so much easier.

Comment by bud...@gmail.com, Jun 22, 2012

Hi When i run the test example project as the steps above, it failed and show the trace below: java.lang.NoClassDefFoundError?: com.jayway.android.robotium.solo.Solo at com.jayway.test.NotePadTest?.setUp(NotePadTest?.java:32) at android.test.AndroidTestRunner?.runTest(AndroidTestRunner?.java:169) at android.test.AndroidTestRunner?.runTest(AndroidTestRunner?.java:154) at android.test.InstrumentationTestRunner?.onStart(InstrumentationTestRunner?.java:529) at android.app.Instrumentation$InstrumentationThread?.run(Instrumentation.java:1448)

Could u help explain what happend ? Tks.

Comment by luckyapp...@gmail.com, Jun 24, 2012

yes I met the problem too!! Can you help me ?

Failure Trace: java.lang.NoClassDefoundError?:com.jayway.android.robotium.solo.Solo at.com.jayway.test.NotePadTest?.setUp(NotePadTest?.java:32) at.android.test.AndroidTestRunner?.runTest(AndroidTestRunner?.java:169) ....................... at.android.test.Instrumentation TestRunner?.onStart(InstrumentationTestRunner?.java:529)

public void setUp() throws Exception{

solo = new Solo(getInstrumentation(), getActivity());
}

Comment by project member renasr...@gmail.com, Jul 12, 2012

@luckyapplelwj, For a fix on the NoClassDefoundError? issue you get please see the following issue:

http://code.google.com/p/robotium/issues/detail?id=237&colspec=ID%20Type%20Stars%20Status%20Priority%20Milestone%20Owner%20Summary

Comment by fangj...@gmail.com, Nov 9, 2012

Hello Renas,

In your video you said you can test an app without the source code, how do you do that? I already downloaded and ran your ExampleTestProject?, it needs the sourcecode of the Notepad to run. I went through the tutorial and could not found example of testing without the source code. Can you briefly describe how to do it or paste a link. Thanks, J-

Comment by project member renasr...@gmail.com, Nov 14, 2012
Comment by fangj...@gmail.com, Nov 28, 2012

Thanks. Found and ran sample project with some problems but all fixed. Now trying to my own project.

Comment by babalola...@gmail.com, Feb 17, 2014

Thank you for this tutorial, it is simple and straight forward.

Comment by chinakal...@googlemail.com, Feb 24, 2014

Nice thanks for this tutorial


Sign in to add a comment
Powered by Google Project Hosting