Road to setup and execute webdriver test scripts on android emulator


Following prerequisites you need to set up before starting.
1. Android SDK must be installed and setup path in your machine and virtual device should be created. For more detail how to setup and create virtual device visit my post “Road to create virtual android device( emulator ) in windows
2. Download selenium server and “android-server-2.32.0.apk” from link “Android server” and save in your machine.
3. Launched your avd device (emulator)

Installation of Webdriver APK into emulator: 

1. Put android “android-server-2.32.0.apk” file under “platform-tools” of installed android directory.
2. Run below command on console to check available devices.
adb  devices
Like below message displayed on your console.
D:\Android\android-sdk\platform-tools>adb devices
List of devices attached
emulator-5554   device

3. Go to “platform-tools” folder of installed android directory and run below command to install android server into mentioned emulator (device) id.
adb -s {{emulator-id}} -e install -r  android-server-2.32.0.apk

adb -s emulator-5554  -e install -r  android-server-2.32.0.apk 
Android driver installed into mentioned driver and you can see into your emulator

4. Start android server in emulator by running below command.
adb -s {{emulator-id}} shell am start -a android.intent.action.MAIN -n -e debug true
5. Run this command to Setup port forwarding:
 adb -s {emulator-id} forward tcp:8080 tcp:8080

Execute Webdriver Test:

package com.test;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class GoogleSearch {
                private WebDriver driver;
                private String baseUrl;
                public void setUp() throws Exception {
                                driver = new AndroidDriver();
                                baseUrl = "";
                                driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

                public void testUntitled() throws Exception {
                                driver.get(baseUrl + "/");

                public void tearDown() throws Exception {



  1. Thanks for this wonderful informative info about Webdriver with Android Emulator....

    Thanks a lot.

  2. Hi,
    Where to give the scripts and how to run the scripts?

    1. I added a sample script run this script as you run webdriver scripts.

  3. can anyone tell how the same can be applied to real devices(Android & iPhone) as i was having some problems after entering a particular URL, it says some error i nwebdriver

  4. Can anyone send sample code for launching selendroid server?


Leave your comments, queries, suggestion I will try to provide solution