How to install Webdriver on Android Emulator on Windows

Following my previous post, I needed to install Webdriver on Android Emulator.  I have Windows 7 installed and most of the instructions were for Linux, so I thought this might be helpful.
image
So even this is pretty straight forward. Let’s run through the steps I followed to install Webdriver:
  1. Download “android-server-2.0.2rc3.apk ” from the following location http://code.google.com/p/selenium/downloads/list.
  2. Copy the above downloaded file into folder “C:\Program Files\Android\android-sdk\platform-tools
  3. Run the “Command Prompt” as administrator.
  4. Execute “cd C:\Program Files\Android\android-sdk\platform-tools
  5. Execute the command “adb install  android-server-2.0.2rc3.apk
  6. We also need to set up Port forwarding, run the command “adb forward tcp:8080 tcp:8080"
  7. Click on the WebDriver app on Emulator and this will make the android server available at “http://localhost:8080/wd/hub”. Opening this URL in Firefox will show up a blank page on success.
  8. Confirm the following settings on your emulator : Settings -> Applications -> Development -> Check "USB debugging", "Stay Awake" and "Allow mock locations".
  9. Launch the emulator, it will have Webdriver installed. When you launch the Webdriver, it will confirm “jetty started

Comments

  1. hi friend.

    thank you for your post. i have already install webdriver in the android emulator. but how how i will run the following test in that webdriver inside emulator from eclipes??
    the code :
    import junit.framework.TestCase;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.android.AndroidDriver;

    public class OneTest extends TestCase {

    public void testGoogle() throws Exception {
    AndroidDriver driver = new AndroidDriver();

    // And now use this to visit Google
    driver.get("http://www.google.com");

    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());
    driver.quit();

    }
    }

    i tried in few ways. but always unsuccessful. so plz tell me in details. i will be really thankful to you if you have time to help me.. thank you

    ReplyDelete
  2. Hey first you need to start the Emulator and run the webdriver application on it. It will show a message "Jetty started". Post then you can run your test.

    Even after trying this, it doesn't work then you can send men the stack trace and then probably I will be able to help you more on this.

    ReplyDelete
  3. i started the webdriver in the andriod emulator 2.2. and then "jetty started" this message is shown. so jetty started successfuly. but when i am running the code them i am geting the error.

    i will send you the error tress but i cant post that here in the blog cus this blug does not allow me to post htmlcode.

    plz share me you email address i will send you by email.so i can send you the error tress

    my email is niloy.cit1@gmail.com

    ReplyDelete
  4. @Niloy Hey you can mail me at nishuverma@gmail.com

    ReplyDelete
  5. hi friend ? i send you two email. have u got those ?
    for using android webdriver on emulator you download which version and from which source ? plz share me the link. the current which i am working now maybe not so stable. cus i am doing some functionality in webdriver in ff but that is not working in android. quite strange.....

    ReplyDelete
  6. @Niloy Probably you need to check the Pros and cons here... http://code.google.com/p/selenium/wiki/AndroidDriver

    ReplyDelete
  7. thank you for your reply. i have gone thought that page already. they are speaking about the version. i am suing 2.2 according to their suggestion. as an example. i am trying to log in in my emulator by andriod webdriver. suppose i set up user name = aaaa and password = bbb.i set them as
    driver.findElement(By.id("Email")).sendKeys("aaaa");
    driver.findElement(By.name("Passwd")).sendKeys("123456");


    but when i run the webdriver in emulator then always this is filling up the password field in www.gmail.com and failed to log in.


    what is the problem with this ?

    ReplyDelete
  8. Dude it's more of your specific issue which you are trying to get rectified.
    Suggest you try with the mobile version of app on the browser(Http://m.gmail.com/) and then use that script.
    All the best in your endeavors.

    In case you have specific selenium issues, try porting to the Selenium community.

    Thanks,
    Nishant Verma

    ReplyDelete
  9. i tried with m.gmail.com but then also the user name and password always puting on the password text box and always failing to log in... why this is happening ?

    ReplyDelete
  10. Hi I am really new to Mobile testing with Selenium. I setup an Emulator and I attempted to execute your sample test above, but when I do I get E/AndroidRuntime( 2979): java.lang.RuntimeException: Unable to instantiate activ
    ity ComponentInfo{com.example/com.example.OneTestActivity}: java.lang.Instantiat
    ionException: com.example.OneTestActivity
    E/AndroidRuntime( 2979): at android.app.ActivityThread.performLaunchActiv
    ity(ActivityThread.java:2585)
    E/AndroidRuntime( 2979): at android.app.ActivityThread.handleLaunchActivi
    ty(ActivityThread.java:2679)
    E/AndroidRuntime( 2979): at android.app.ActivityThread.access$2300(Activi


    Can you help?

    ReplyDelete
  11. Hey you can mail me what are you doing and what machine you have OS etc...

    Also I think in the latest android sdk you need to start webdriver using command prompt.

    ReplyDelete
  12. Hi,

    When i create the Test project for testing using Android Driver, in Test project what external jars i have to add.
    Inside selenium-2.5.0, there are selenium-java-2.5.0.jar, selenium-java-2.5.0-srcs.jar and libs folder. Inside libs folder, there are also many jars. Should i have to add all the jars as external jar to the test project.

    If i add all the jars, then when i build the test project, it takes a long time to build and then finally i get the error: Unable to execute, not sufficient heap space.

    If i add only the two jars(selenium-java-2.5.0.jar, selenium-java-2.5.0-srcs.jar ) or single jar(selenium-java-2.5.0.jar), then i get the error:

    [2011-09-19 18:31:58 - AndroidTest] Dx
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.lang.IllegalArgumentException: already added: Lorg/openqa/selenium/interactions/Action;
    [2011-09-19 18:31:58 - AndroidTest] Dx at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
    ..........
    ..........

    [2011-09-19 18:31:58 - AndroidTest] Conversion to Dalvik format failed with error 1


    Please help me to solve the problem.

    ReplyDelete
  13. Hi,

    for what concerns the "UNEXPECTED TOP-LEVEL EXCEPTION" problem, I've just found out that the selenium-java .jar file contains double instances of the same .class files for some reason.

    I'm trying to build it from the source and let's see what happens.

    ReplyDelete
  14. I have same problem! Please, help.

    ReplyDelete
  15. I am new to Selenium2. I have a requirement to test my application on android. I did all the setup that mentioned in the wiki,But it is not working. Can you please help me out in this issue. Or provide any useful links containing how to automate tests in mobile apps.

    Thanks in advance,
    Eeeshwar

    ReplyDelete
  16. Unable to use cssSelector or xpath with AdroidDriver.
    Scenario:I was trying to sign-in to mail.in.com, but unable to click on Sign-in button. Here is the code I tried. Kindly reply on this issue

    driver = new AndroidDriver();
    driver.get("http://mail.in.com");
    Thread.sleep(1000);
    driver.findElement(By.id("f_id")).sendKeys("seleniumforum_Nageswar");
    driver.findElement(By.id("f_pwd")).sendKeys("XXXXX");
    driver.findElement(By.xpath("/html/body/div[@id='main']/div[1]/div[1]/div[1]/p/a[5]")).click();

    (OR)


    driver = new AndroidDriver();
    driver.get("http://mail.in.com");
    Thread.sleep(1000);
    driver.findElement(By.id("f_id")).sendKeys("seleniumforum_Nageswar");
    driver.findElement(By.id("f_pwd")).sendKeys("XXXXX");
    driver.findElement(By.cssSelector("input.signin")).click();

    ReplyDelete
  17. Hi Nishant,

    I am new to this Android Webdriver Technology,here i had set up the enviroment and trying to execute the sample script below,but getting error has "Authentication required to access the internet in this system" in the emulator.

    Before ruuning it started the webdriver application in the emulator and established the connection between the localhost server also,but it giving this error. Can u please help me in this out.

    And one more clarification,when i am trying to access internet simply through android browser i am able to browse something.But when executing through script only i am getting the error.

    import junit.framework.TestCase;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.android.AndroidDriver;

    public class OneTest extends TestCase {

    public void testGoogle() throws Exception {
    AndroidDriver driver = new AndroidDriver();

    // And now use this to visit Google
    driver.get("http://www.google.com");

    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());
    driver.quit();

    }
    }

    ReplyDelete
  18. Hi Nishant,

    Do you know how to start webdriver application on the android emulator from command line?

    I am trying to run a test from java and want to make everything automated. I have installed the webdriver apk on the emulator.

    Appreciate your help!!

    -Krishna

    ReplyDelete
  19. Hey guys, i don't know how to create the correct project for "OneTest.java" from selenium official website.
    I follow the guide from http://code.google.com/p/selenium/wiki/AndroidDriver
    to setup the example code of
    using remote server approach ,
    but it is not detailed enough.
    Can everyone mail me your step or the complete project folder?

    my mail: link_5201314@hotmail.com

    ReplyDelete
  20. Hi Nishant, I am new in Android Testing. I am using C# as scripting language but facing problem to initiate from code, may you please help me out to start the code for same. I have written under given code but not working @ line no 20 showing Android Device not exists.

    public class UnitTest1
    {
    private IWebDriver WebDriver;


    [TestInitialize]
    public void TestInitializeAttribute()
    {
    WebDriver = new AndroidDriver();
    var browser = new RemoteWebDriver(new Uri("http://localhost:8080/wd/hub/static/resource/hub.html"), new DesiredCapabilities("Android", "", Platform.CurrentPlatform));
    WebDriver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
    }

    [SetUp]
    public void TestSetUp()
    {
    WebDriver.Navigate().GoToUrl("http://www.google.co.uk");

    }

    ReplyDelete
  21. Hi Nishanth. I am working for the android automation for mobile web and app projects.

    Can you please help regarding the below :

    I am in the means of setting up of android drivers and followed the same steps as mentioned in the url : http://code.google.com/p/selenium/wiki/AndroidDriver

    1) downloaded the android SDK for windows and unpacked and placed in the path of selenium repository 2) Set up the emulator and created the new AVD ( android virtual device ) 3)Installed the webdriver apk 4)port forwarding in order to forward traffic from the host machine to the emulator. In a terminal type:

    $./adb -s forward tcp:8080 tcp:8080

    5) This will make the android server available at //localhost:8080/wd/hub from the host machine.

    But when i went to localhost:8080/wd/hub it displayed error 404 : not found

    Let me know why this is happening ? anything i missed ?

    When taps on webdriver in android emulator it says webdriver ready but not displaying message as Jetty started.. can you also let me know why Jetty is not started ?

    Is this necessary to start selenium standalone server and JDK to be installed to which jetty will communicate to the hub ?

    Thanks in advance
    Prasad

    ReplyDelete
  22. Hi Nishanth,

    I have the same problem as in previous comment. Do you have any idea what's wrong? And thank you for this post!

    ReplyDelete
  23. I tried as you said

    but I got the following error

    error: device not found
    -waiting for device-

    ReplyDelete

Post a Comment

Your comments will be reviewed and then published !

Popular posts from this blog

The 3 qualities that will always help you become better at almost anything…

Embracing the Journey: Finding Joy in the Process

How to install Android Emulator on Windows