如何使用Junit运行AndroidDriver测试?

时间:2012-03-22 14:15:09

标签: android android-emulator junit eclipse-plugin android-2.2-froyo

我一直按照以下说明操作:

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

到目前为止,我已经成功完成了以下工作:

  • 已安装的Android SDK
  • 更新了
  • 制作并运行AVD图像
  • 安装了Eclipse和ADT插件,但尚未学习Eclipse。 (我正在尝试仅从命令行编译内容。)
  • 在Android模拟器上运行模拟
  • 使用adb -s -e install -r
  • 在Emulation上安装WebDriver APK
  • 为上述
  • 设置端口转发
  • Webdriver已启动,显示在模拟器上
  • 已下载selenium-java-x.jar
  • 已下载junit-x.jar
  • 确定用于编译代码的类路径
  • 使用javac编译,我不知道这是否正确:

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

这是我的测试:

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();
  }
}

现在我被困在这个部分: http://code.google.com/p/selenium/wiki/AndroidDriver#Build_the_Android_Code

我在哪里运行这些命令?例如$。/ go android_client等。我想我只需要知道如何正确编译以及如何将此测试转发给模拟器。但我可能完全走错了路。

我的版本是:

  • Eclipse:3.7.1
  • Selenium服务器:2.17.0
  • AndroidDriver:2.16.0
  • Android SDK工具修订版16

1 个答案:

答案 0 :(得分:1)

记住你到目前为止采取的步骤和摘录:

  

现在我被困在这个部分:   http://code.google.com/p/selenium/wiki/AndroidDriver#Build_the_Android_Code

     

我在哪里运行这些命令?例如$。/ go android_client等

该部分用于构建Andriod WebDriver代码。我建议您不要尝试运行这些命令,因为不需要该部分来运行测试,这是您从下面的摘录中收集的意图:

  

我想我只需要知道如何正确编译以及如何编译   将此测试转发给模拟器。但我可能完全错了   轨道。

基本上你已经完成了所有的基础工作,此时你需要做的就是运行测试文件。

你可以尝试:

有关在Eclipse here上启动和运行的一些有用信息。假设您正在运行Eclipse(Junit已经插入了eclipse),您可以在Eclipse的Package Explorer窗口中右键单击您的测试文件,然后单击Run As> Junit测试。

希望这有帮助。