Friday 23 May 2014

Simple steps to automate test cases using robotium


  1. Create one workspace or Directory named as “Workspace_Robotium”
  2. Start eclipse.
  3. Choose workspace.
  4. New -> Project -> New Project -> Android application project
  5. Application Name -> “Testing”
  6. Project Name -> “Testing_Robotium
  7. Next ...
  8. New -> Android Test Project
    Project Name -> “Testing”
    Next . Select “this project”
  9. Copy/ Take Apk to test
  10. Open as Archive
  11. Delete META-INF file
  12. Change the sign and install the Apk
    1. Copy ~/.android/debug.keystore to apk containing directory.
    2. jarsigner -verbose -keystore debug.keystore ApkUnderTest.apk androiddebugkey
    3. jarsigner -verify ApkUnderTEst.apk
    4. Create tmp Folder
    5. zipalign -v 4 ApkUnderTest.apk tmp\ApkUnderTest.apk
    6. adb install tmp/ApkUnderTest.apk
  13. Android Test project
    1. Build Path-> android Build path
  14. Android test Project
    1. Change Activity launch name
    2. Change Android Manifest .xml file \
    3. <instrumentation
        android:targetPackage="com.Example.ApplicationTesting"
    with
    <instrumentation
    android:targetPackage="com.Example.ApplicationToTest"
    This you will get it from Logcat.
  15. Make a class and Paste the code.
package com.example.testing_robotium.test;


import android.test.ActivityInstrumentationTestCase2;
import android.view.View;

import com.jayway.android.robotium.solo.Solo;

public class Test_sensor_simple extends ActivityInstrumentationTestCase2 {

// this is the name of the Activity u are launching i.e the main activity of the android App
// u have to place the name of the main activity of the application under test .

private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.invensense.app.sensorsimple.SensorSimpleActivity";
// this will check if the Activity u have mentioned is present on the Device
private static Class launcherActivityClass;
static {
try {
launcherActivityClass = Class
.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

public Test_sensor_simple() throws ClassNotFoundException {
super(launcherActivityClass);
}

//initialize the Robot class
private Solo solo;

// this is to start the activity which need to be Tested
@Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}

public void testDisplayBlackBox1() {
solo.sleep(3000);
solo.clickOnCheckBox(2);
solo.scrollToSide(Solo.RIGHT);
solo.clickOnText("Game", 3);
solo.sleep(1000);
solo.clickOnText("Normal");
solo.sleep(5000);
}

// this is the test Cases

//this is to close the Activity After the Test cases are completed
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}

}


No comments:

Post a Comment