Robotium can detect the messages that are shown on the screen (Toasts) it supports
Android features such as activities, menu, and context menu.
Both AUT and Project run on the same JVM, with the help of Dalvik Virtual Machine
(DVM) (DVM is the software that runs the Apps on Android devices and Emulators).
At first we need to have Android Environment to make application run before starting up
with Robotium framework.
Android Environment setup:
Checklist:
1. JDK - F:\Robotium\RobotiumSoftwares
2. JRE - F:\Robotium\RobotiumSoftwares
3. Eclipse
Integrated
with
F:\Robotium\RobotiumSoftwares\RobotiumSoft_Dump
4. SDK - F:\Robotium\RobotiumSoftwares\SDK
ADT
Setup Environmental Variables for Java: To make the java class accessible and
to run the java code.
For Windows 7
1. Select Computer from the Start menu.
2. Choose System Properties from the context menu.
3. Click Advanced system settings > Advanced tab.
4. Click on Environment Variables, under System Variables, find PATH, and click on it.
5. In the Edit windows, modify PATH by adding the location of the class to the value
for PATH. If you do not have the item PATH, you may select to add a new variable
and add PATH as the name and the location of the class as the value.
6. Reopen Command prompt window, and run your java code.
Windows XP
1. Start -> Control Panel -> System -> Advanced.
2. Click on Environment Variables, under System Variables, find PATH, and click on it.
3. In the Edit windows, modify PATH by adding the location of the class (C:\Program
Files\Java\jdk1.7\bin) to the value for PATH. If you do not have the item PATH, you
may select to add a new variable and add PATH as the name and the location of the
class as the value.
4. Close the window.
5. Reopen Command prompt window, and run your java code.
Note: Open Dos prompt and type below command to make sure Java is sworking in the machine
SDK Setup:
To make Android application work in the machine, SDK should be configured. There are two
ways to do Through Command Line and another through SDK.exe file available in the
bundle
To configure SDK through Command line:
1. Go to the path where SDK is installed
2. Copy the path till Platform-tolls and add to the PATH in System Variables
<Path>/SDK/tools.
3. To check its working fine, Open DOS Command and type below command
>Android: SDK Manager will open and it will automatically update latest APIs.
After Successful completion of the Android Setup, Now we have to configure ADB, ADB
serves as a communication channel between user and Android device or Emulator.
Eclipse - Yes
ADT - yes
SDK - yes
Junit(4.5.Jar) - Yes
Robotium(Solo-4.3.1.jar ) - Yes
By this time we should have Eclipse, ADT and SDK in the bundle which was downloaded.
UnZIP it to a safe location on your machine. Since bundle has built in ADT we need not
have to configure/Install ADT explicitly.
Adding the Android SDK location to Eclipse:
To add the Android SDK to Eclipse, follow below steps:
1. In Eclipse, under the Window menu, click on Preferences.
2. Check the Android tab (The presence of this tab clearly indicates that the Android ADT
plug in is successfully installed) and a window will appear, as shown in the following
screenshot.
3. Browse and give the SDK location (Location where the ADT bundle is Un-Zip) the SDK
location informs Eclipse where the Android SDK is located in the system.
4. The list of SDK targets will be reloaded only when the proper SDK location is provided
and the Apply or OK button is clicked on.
Note: It is best practice run the SDK manager once before providing the location so that all the latest APIs are
downloaded.
2. Click on Device Definition to configure the AVD. We can create customize AVD, by
clicking new Devices.
3. Click on Create AVD and observe Android Virtual device Tab, AVD definition will be
visible in it as shown below.
4. Click on Start and launch the AVD.AVD thus created will appear as shown below.
By this point, we should have a working setup of the Android and Robotium Environment.
Now we have to start with Robotiums test case writing and execution.
As discussed earlier Robotium automation can be executed for both White Box
Testing(where the Sourcecode is avaliable) and Black Box Testing(Where only .Apk file is
avalaibale)this very feature of Robotium makes it more relaibale and robust framework.
Checklist
1. Install AUT (Application Under Test). Apk file
2. Package Name
3. Main Activity Name
Step1:Create Test Project:
1. Click on file->New->Project->select Android Test Project(as shown below)
3. Select this project(Note: when we start Eclipse for the very first time this window will
be blank)
4. Select the API for the AUT to be tested which was configured earlier (This
configuration will design the AVD later on). Click on finish.
5. On clicking Finish button a n Android Test Project will be created with no package, but
this will throw an error as shown below.
Note: Because it is new workspace and eclipse is not able to get selected Android resources for first test project. We can
solve this issue by following option:
Create another Test Project & eclipse will automatically get selected resource (for new one) & not show error for second
created Test Project (we can use second one for our work).
2. Once the Package is created Package Explorer looks as below. Add the Test case to
the package.
3. On creating the Package, a Package and a class are created with their corresponding
names.
4. Once the Package is created we have to import Robotium jar files to import Robotium
solo class into our test suit as shown below.
a. Right click on the project->Build Path->Configure Build Path
b. In properties Test Project window, Unfold Resource and select Java Build
Path.
c. In Libraries tab click on Add External JARs and browse the robotium Solo
jar file.
d. In Order and Export tab select the check the Robotium solo jar file and
click on OK button.
3. Open Manifest.xml file from the Project tree, Copy the below code in it and make
changes in - <instrumentationandroid:targetPackage="<Package Name>" and save
it
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sampleproject.test.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="18" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="<PackaheName>" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
</application>
</manifest>
>adb devices
>adb install <path>/<filename>.apk
3. Right Click on Project -> Run As->Android JUnit Test. It will automatically run the test
case. Logs can be observed in Console window