Skip to main content

Development

Mobile Automation Testing using Selenium Webdriver

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.

Prerequisite:-

–       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”):-

Android_SDK_FolderStructure

Android_SDK_FolderStructure

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 <Extracted SDK folder>/sdk/tools.

(I) Run android create avd -n <name of device> -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 <name of device>&, 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 <Extracted SDK folder>/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:-
http://code.google.com/p/selenium/downloads/list

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.

Thoughts on “Mobile Automation Testing using Selenium Webdriver”

  1. Nice article, but can you pls update a steps (initial to end) how test using real device without using apk.

  2. Sohit Kanwar Post author

    Hi Chethan,

    Thanks for the response. If you are looking to execute webdriver script on real device.

    Follow the same steps as mentioned above barring Step 3:- Setup the Android Emulator.

    Then connect your phone with usb device and when you run Step 4 :- (I) Run adb devices, you will get to see serialID of your device.

    Follow the same steps after that. You need to install web driver apk in your device because this acts as a mediator between device and your webdriver script.

    Let me know in case if you are unable to execute the script.

  3. This very helpful. Thank you for the details information.

    Can you please also add steps to run the test on ios devices/simulator.

  4. I have a slightly different situation. We are using the Microsoft ALM and need to run the selenium test through visual studio. I can run on an actual device using Appium, but not on an emulator. Our application is a web application which needs to run on Chrome, Firefox or IE. Is there a way to test on an emulator through Visual studio/Appium? Thanks

  5. It could be better if you make the video of it. So, it will help to understand easily by watching the videos.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Sohit Kanwar

More from this Author

Categories
Follow Us
TwitterLinkedinFacebookYoutubeInstagram