Wednesday, April 22, 2015

Robotium : How to automate an Android Application using Record and playback approach

In our last post we see how to install Robotium on our Eclipse IDE. In this post we will explain on how to record an android application and playback the script.

Step 1 : Open Eclipse IDE. Before started recording we need to run the Android virtual device. Click on the Android Virtual device icon.

image

AVD manager window is displayed and start a device that is already configured. How to configure a Virtual device will be posted later in separate post. Select a device and click on Start button.

image

Launch Options window is displayed and click on Launch button.

image

Virtual device will start for Launching.

image

image

Now minimize the virtual device window, close AVD window and proceed for Robotium recording.

Step 2 : Go to File > New > Other

image

Step 3 : Click on Android – Robotium Recorder from New Window. Select New Robotium Test.

Step 4 : Click on Next button.

image 

Step 5 : A pop up dialog is displayed with the message “Please Select the root Java JDK folder”. This message is only displayed if JDK folder is not defined and configured. Click on OK button.

image

Step 6 : Java JDK window is displayed. Locate the JDK folder on the machine. Click Ok button.

image

Step 7 : Robotium Recorder window is displayed and select the apk file. In our case we have downloaded android calculator apk file from this location. Select the apk file and enter the project name. Click on Next button.

image

Step 8 : Click on New Robotium Test button.

image 

Step 9 : Recording Started. Wait for the application starts at Virtual device.

image

image

Step 10 : Go to Virtual device window and note that application will start on that window.

Step 11 : Enter 4 at First text box

Step 12 : Click on the second text box and enter 5 at second text box

Step 13 : Click on Multiply button.

Step 14 : Result will be displayed at Result text box.

Step 15 : In order to verify the result click on the Result text box. It will create an assert script.

image 

Step 16 : Note that steps are written at plain text and click on Stop recording button.

image

A window may appear and click on OK button.

image 

Step 17 : Click on Save button

image

Step 18 : A window is displayed to ask for Test Case name. Enter Test Case name as “Multiplication” and click on OK button.

image

Step 19 : Click on Finish button.

image

Step 20 : Code will be generated for this script at Eclipse editor. Expand the project of the package explorer window.

image

Step 21 : Double click on the class name “Multiplication.java”. We see the step by step script on the code. We will explain about code on future post.

image 

Step 22 : Now Run the script. Right click on the Script name and click Run as > Android JUnit test.

image

Step 23 : Go to Virtual device window and inspect that script will run and execute test.

image image

Step 24 : Result is displayed at JUnit Editor.

image

That’s all for now. Our next Robotium related post, we will show on how to refactor the Robotium script and write more manageable test.

Happy Automation day with Robotium …!!!