Executing Your Script on android Emulator or device in Selenium Web Driver

Nowadays, compatibility testing is in great demand as it gives us the confidence to say whether the application is usable across multiple platforms.
One of the most used platforms available in today’s world is Mobile. So the question here is whether the application is usable across different Mobile platforms?
There are n number of Mobile devices available with x resolution having y operating system. So practically, it’s not feasible to have all the n*x*y number of devices to do a compatibility test on.
That’s the reason Mobile simulators have come into the picture so if I have to test my application on that many  devices, I can do it by simulating the required features.
Let’s look at the task that needs to be performed:-
Selenium WebdriverObjective: – To test the web application on Mobile emulator using Selenium Automation tool.
Resources: – Selenium, Android SDK, Eclipse IDE
Solution: – I will be using Java as the scripting language and Junit framework. Using Eclipse IDE, I will be executing the script which in turn runs on the Mobile emulator/device.
–       Should have jdk 1.6 or latest version.
–       Eclipse with Junit runner configured
Step 1:- Install the Android SDK
Android SDK can be downloaded from the link http://developer.android.com/sdk/index.html
Step 2:- Unzip the downloaded file
Unzip the file in your local system and the following structure can be seen (Say “D:/Android SDK”):-

Step 3:- Setup the Android Emulator
Open Command prompt and do the following:-
Go to the extracted folder as shown in the above screenshot and navigate to /sdk/tools.
(I) Run android create avd -n  -t 12 -c 100M
Where      -n: specifies the name of android virtual device
   -t: specifies the platform target. For an exhaustive list of targets, Run: android list targets
   -c: specifies the SD card storage space.
Once you run this command, you will be prompted with a message
“Do you wish to create a custom hardware profile [no]”, enter no
(II) Run emulator -avd &, this command will open the android emulator as shown below:-
Android Emulator

Android Emulator
Step 4:- Download and Install the Web Driver APK
Web Driver APK file can be downloaded from the link http://code.google.com/p/selenium/downloads/list
Open Command prompt and do the following:-
Go to the extracted folder as shown in the above screenshot and navigate to /sdk/platform-tools.

(I)   Run adb devices
This command will list all the recognized serialID of emulator or device.

(II)  Run adb -s <serialId> -e install -r android-server.apk, this command will install web driver APK into the emulator.

(III) From the Emulator UI, open the web driver APK. You will be able to see the message as “WebDriver Ready”.

(IV)  Run adb -s <serialId> forward tcp:8080 tcp:8080, this command will do the port forwarding in order to forward traffic from the host machine to the emulator.

Note: - Now we are done with the Android environment setup. Let’s go ahead and execute the test.

Step 5:- Execute the selenium script from Eclipse IDE

(Assuming the Java project has been created and the Junit test scripts are placed in Eclipse IDE)
To compile and run the junit test, you need to import library files in Eclipse IDE for the project.
The library files “selenium-java-X.zip” can be downloaded from the link:-

To add the library files in Eclipse IDE, do the following:-
Right click on project -> Build Path -> Configure Build Path -> Libraries -> Add External Jars -> select the downloaded Jars.
After you are done with importing libraries.
Go to Run As and select Junit runner.
You can see the test will get executed in the emulator.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s