Robotium and testdroid recorder

In this post I will show you how to automate android application using robotium framework with testdroid recorder.
Testdroid recorder is capture user action , generate reusable android test case into robotium framework.
For more detail about Testdroid visit link (click here)[http://testdroid.com/product/testdroid-recorder#0]

Prerequisites:

1.Eclipse should be installed in your machine.
2.Android SDK should be installed.
3.ADT Plug-in installed in to Eclipse.

Testdroid installation:

1.Start Eclipse and go to Help –> Install New Software
2.Click Add button; enter to field asking you a site to work with.
3.Fill in “Testdroid plug-in” for the Name
4.For the Location provide URL to Testdroid repository: [http://www.testdroid.com/updates/]
5.Click ok button.
6.Click next button. During installation you must see below warning pop up
7.Click on “OK” button of warning popup window.
8.After successful installation restart your eclipse.

Creating project in eclipse:

1.Create new android test project.
2.Click next button.
3.Enter project name and click on next button.
4.Chose Android API and click finish button.

Run Emulator:

Run your emulator having API 11 or as per your selection.

Recording test Script:

1.Goto File menu and select New > Other and select option “New Robotium Test”.
2.Click next button.
3.Enter user name and password of Testdroid application and Click Authorize button.
4.Click next button. Browse your apk file and click next button again.
5.Select recording method name and click on recording button. Your apk file will install in opened emulator , launch the application on emulator and start the recording.
6.After recording click on stop recording button and click on finished button. Your recorded scenario automated converted in java junit test and save in eclipse like as below java code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import android.test.ActivityInstrumentationTestCase2;
import android.app.Activity;
import junit.framework.AssertionFailedError;
import com.bitbar.recorder.extensions.ExtSolo;

public class NewRobotiumTest extends ActivityInstrumentationTestCase2 {

  private static final String LAUNCHER_ACTIVITY_CLASSNAME = "com.gorillalogic.monkeytalk.demo1.RootActivity";
  private static Class launchActivityClass;
  static {
         try {
                 launchActivityClass = Class.forName(LAUNCHER_ACTIVITY_CLASSNAME);
         } catch (ClassNotFoundException e) {
                 throw new RuntimeException(e);
         }
  }
  private ExtSolo solo; // ExtSolo is an extension of Robotium Solo that helps
                                               // collecting better test execution data during test
                                               // runs

  @SuppressWarnings("unchecked")
  public NewRobotiumTest() {
         super((Class) launchActivityClass);
  }

  @Override
  public void setUp() throws Exception {
         super.setUp();
         solo = new ExtSolo(getInstrumentation(), getActivity(), this.getClass()
                         .getCanonicalName(), getName());
  }

  @Override
  public void tearDown() throws Exception {
         solo.finishOpenedActivities();
         solo.tearDown();
         super.tearDown();
  }

  public void testRecorded() throws Exception {
         try {
         } catch (AssertionFailedError e) {
                 solo.fail("NewRobotiumTest.testRecorded_scr_fail", e);
                 throw e;
         } catch (Exception e) {
                 solo.fail("NewRobotiumTest.testRecorded_scr_fail", e);
                 throw e;
         }
  }

}