ANDROID webdriver with selenium

11,279

Neha,

first things first, have you read the relevant wiki page for Android driver on the Selenium project? http://code.google.com/p/selenium/wiki/AndroidDriver

As it says, the last version of Android WebDriver to support Android 2.2 is release 2.16 of the APK, http://code.google.com/p/selenium/downloads/detail?name=android-server-2.16.apk

If you would prefer to use the current versions of the Android driver I would recommend you try using newer versions of Android. As you may know, it's easy to create a new emulator, a new AVD as they're also known. The AndroidDriver wiki page explains that because of a bug in the 2.3 emulator, WebDriver will not work in it. However it will work on a real device running 2.3 (or higher)

The next thing to check is whether the AndroidManifest.xml for the target app has the Internet permission. [Note: I have this permission in both AndroidManifest.xml files, the one for the dummy target app and for the TestProject to be safe, however in my testing I found the one that seemed to matter was the one for the app.]

<uses-permission android:name="android.permission.INTERNET" />

AFAIK the Android example's app is called SimpleApp.

Another tip is to try and capture the HTML for the contents of the WebView that's loaded once WebDriver has tried to get the google homepage. Here's a simplistic way to do this, I've added the call after the existing driver.get(...)

driver.get("http://www.google.com");
Log.i("WebDriverDemo", driver.getPageSource());

It's simplistic because the call to Log the results has a restriction on how much it can write to the log, so large HTML source may be truncated. However the information in the log may be enough for you to identify the problem.

If you're still stuck once you've either tried using 2.16 of Android-WebDriver in your 2.2 emulator, or the current version of Android-WebDriver in an emulator with a later of Android e.g 4.x, perhaps you could add the stack trace here.

Good luck

Julian.

PS: I provided a similar answer to a parallel earlier question by Neha. I've suggested Neha updates that question with a link to this newer version.

Share:
11,279
Neha
Author by

Neha

Updated on August 03, 2022

Comments

  • Neha
    Neha almost 2 years

    I am running the sample test project given in the android sdk for web driver.the code is:

    package simple.app.test;
    
    import android.test.ActivityInstrumentationTestCase2;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.android.AndroidWebDriver;
    
    import simple.app.SimpleAppActivity;
    
    public class SimpleGoogleTest extends ActivityInstrumentationTestCase2<SimpleAppActivity> {
        private WebDriver driver;
        private WebDriver googledriver;
    
        public SimpleGoogleTest() {
            super("simple.app", SimpleAppActivity.class);
        }
    
        @Override
        protected void setUp() throws Exception {
          driver = new AndroidWebDriver(getActivity());
        }
    
        @Override
        protected void tearDown() {
           driver.quit();
        }
    
        public void testGoogleWorks() throws Exception {
            driver.get("http://www.google.com");
            Thread.sleep(10000);
            WebElement searchBox = driver.findElement(By.name("q"));
            searchBox.sendKeys("Android Rocks!");
            searchBox.submit();
            String title = driver.getTitle();
            assertTrue("Got title: " + title, title.contains("Google"));
           assertTrue(driver.findElements(By.partialLinkText("Android")).size() > 1);
        }
    }
    

    I am getting the following issue:

    1. Android2.2-NoSuchMethorError
    2. Android2.3.1-process crashed.

    Please help me to resolve these issues.