1

I tried a example provided in the, Android app testing through Selenium, i have included the selenium-java library and android-webdriver apk also installed in emulator, but when try with the sample code provide in the forum i got error in AnroidWebDriver import, in selenium library only AndroidDriver class is available, so where could i get the AdroidWebDriver jar. Plz assit.

Note: Selenium library is very latest one.

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());
    }
........................,,,,,
  }
JulianHarty
  • 3,178
  • 3
  • 32
  • 46
Jeevanantham
  • 984
  • 3
  • 19
  • 48

1 Answers1

1

There are two variations of the Android Driver:

  • AndroidDriver() which you use on your Personal Computer e.g. your laptop, workstation, etc. which provides the richest and most complete set of capabilities for your tests.
  • AndroidWebDriver() which runs on your Android device, this wraps a WebView component to provide the basic core functionality.

The example code that comes with the Android SDK and the optional support for Selenium/WebDriver runs some basic tests on the device. The tests are compiled as an Android program which extend ActivityInstrumentationTestCase2. AndroidWebDriver() is contained in sdk/extras/google/webdriver/android_webdriver_library.jar (and the Javadocs are in sdk/extras/google/webdriver/android_webdriver_library-srcs.jar

So, if you want to run your tests on your Android device, then you need to include android-webdriver-library.jar in your project. Perhaps the simplest way is to copy this jar into your test project's libs folder.

However, if you would like to run your tests on your Personal Computer you can modify the example code to use AndroidDriver instead of AndroidWebDriver. You also need to change your base class e.g. to use Junit 3 or Junit 4. I have posted a sample test as an answer to another question on Stack Overflow here Having difficulty in finding Elements using Xpath and CSS in Selenium Android Webdriver Testing

Community
  • 1
  • 1
JulianHarty
  • 3,178
  • 3
  • 32
  • 46
  • I tried with AndroidDriver too, as provide in [Sample Android Test](http://android-developers.blogspot.in/2011/10/introducing-android-webdriver.html), but ide throws _no suitable constructor found for ActivityInstrumentationTestCase2_ and _no suitable constructor found for AndroidDriver_. pls assist – Jeevanantham Apr 05 '13 at 08:26
  • Have you created your test project correctly? in http://android-developers.blogspot.in/2011/10/introducing-android-webdriver.html they say **create the Android test project that will contain the tests.** Please update your question with the exact error message from your IDE together with the code you're trying to compile. At the moment I don't have enough information from your comment e.g. why are you using AndroidDriver in an Android test case? you would need to use AndroidWebDriver. Finally for now, which libraries, precisely, are you using? e.g. are you linking with android.jar? – JulianHarty Apr 05 '13 at 12:44
  • PS: I suspect the example is incorrect in http://android-developers.blogspot.in/2011/10/introducing-android-webdriver.html for instance the constructors for AndroidDriver http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/android/AndroidDriver.html don't accept an Activity, whereas AndroidwebDriver does http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/android/library/AndroidWebDriver.html – JulianHarty Apr 05 '13 at 12:59