2

I've been following the instructions at:

http://code.google.com/p/selenium/wiki/AndroidDriver

And I've managed to get the following working so far:

  • Installed Android SDK
  • Updated it
  • Made and ran an AVD image
  • Installed Eclipse and ADT plugin but haven't learnt Eclipse yet. (I'm trying to compile things from the command line only.)
  • Ran the emulation on the Android emulator
  • Install WebDriver APK on Emulation using adb -s -e install -r
  • Set up portforwarding for the above
  • Webdriver started is displayed on the emulator
  • Downloaded selenium-java-x.jar
  • Downloaded junit-x.jar
  • Determined classpath for compiling the code
  • Compiled using javac, I don't know if this is right:

    javac -classpath c:_projects\junit\junit-4.10.jar;c:_projects\selenium-java\selenium-java-2.17.0.jar OneTest.java

Here is my test:

import junit.framework.TestCase;

import org.openqa.selenium.WebDriver; //VERY IMPORTANT. This line is not in the example on the Selenium AndroidDriver website.
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 
  {
    WebDriver 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();
  }
}

Now I'm stuck on this section: http://code.google.com/p/selenium/wiki/AndroidDriver#Build_the_Android_Code

Where do I run these commands? For example $./go android_client etc. I think I just need to know how to compile properly and how to forward this test to the emulator. But I could be totally on the wrong track.

My versions are:

  • Eclipse: 3.7.1
  • Selenium server: 2.17.0
  • AndroidDriver: 2.16.0
  • Android SDK Tools Revision 16
Adamantus
  • 813
  • 1
  • 12
  • 30

1 Answers1

1

Keeping in mind the steps you have taken so far and this excerpt :

Now I'm stuck on this section: http://code.google.com/p/selenium/wiki/AndroidDriver#Build_the_Android_Code

Where do I run these commands? For example $./go android_client etc

The section is for building the Andriod WebDriver code. I suggest that you do not try running these commands as that section is not required to run the tests, which is your intention as gathered from the excerpt below :

I think I just need to know how to compile properly and how to forward this test to the emulator. But I could be totally on the wrong track.

Basically you have done all the foundation work and at this point all you need to do is run the test file.

You could try:

There is some useful information about getting up and running on Eclipse here. Assuming that you have Eclipse running (Junit is already plugged in with eclipse) , you could right click your test file in the Package Explorer window on Eclipse, then click Run As > Junit Test.

Hope this helps.

Community
  • 1
  • 1
self-babush
  • 585
  • 3
  • 13
  • Ok. I tried to right click > run as Junit > I got: Errors exist in required project. android_test. Proceed with launch? The way I've created my project is by adding all the jars I think are needed in sources. So I thought I needed selenium_java_x.jar plus junit-x.jar so I added those in. But running generates thousands of errors for things which are not found. Like: "AfterMethod cannot be resolved to a type...". The test has no other required sources apart from those. So am I creating a junit project or android project, and do I need all of these sources? – Adamantus Apr 03 '12 at 12:12
  • You should be creating an Android Project.You could add the selenium_java jar. I don't think you would need the junit-x.jar. You should see the options you see when you right click the file and click Run As . – self-babush Apr 03 '12 at 13:22
  • Also you have mentioned about "AfterMethod".which I don't see used in the test script you have pasted.Do you have other files in the workspace. – self-babush Apr 04 '12 at 06:04
  • There are thousands of those which are caused by importing the jars into the project. AfterMethod was just the first one. I decided to award you with the bounty, congratulations. – Adamantus Apr 04 '12 at 15:21