9

我正在寻找一个在 android 上的浏览​​器模拟库,它可以处理类似的事情

  • 加载网站 (http/https)
  • 重定向:HTTP(3xx 状态码)、JavaScript、HMTL 标签
  • 填写html表单
  • 简单的 html 解析(可以回退到 JSoup 那个)

HttpUnitHtmlUnit就可以了,但它们都很难在 android 上运行。

除了 (Android)HttpClient 之外还有其他选择吗(因此我自己做了很多上述工作)?或者我可以以某种方式使用android webkit/浏览器吗?

提前致谢!

4

1 回答 1

2

我建议你看看AndroidDriver for selenium。这似乎是一种使用 Android 测试框架轻松测试 Web 应用程序的简单方法。

您必须使用包含 WebView 的 Activity 才能测试 HTTP/HTTPS 网站。驱动程序使用此 Activity 实例化:

WebDriver driver = new AndroidWebDriver(getActivity());

这是一个示例测试,引用自上面的链接:

 public void testGoogleWorks()
    // Loads www.google.com
    driver.get("http://www.google.com");
    // Lookup the search box on the page by it's HTML name property
    WebElement searchBox = driver.findElement(By.name("q"));
    // Enter keys in the search box
    searchBox.sendKeys("Android Rocks!");
    // Hit enter
    searchBox.submit();
    // Ensure the title contains "Google"
    assertTrue(driver.getTitle().contains("Google"));
    // Ensure that there is at least one link with the keyword "Android"
    assertTrue(driver.findElements(By.partialLinkText("Android")).size() > 1);
}
于 2012-03-15T15:14:06.113 回答