我正在寻找 android 上的浏览器模拟库,它可以处理类似的事情
- 加载网站 (http/https)
- 重定向:HTTP(3xx 状态代码)、JavaScript、HMTL 标记
- 填写 html 表格
- 简单的 html 解析(可以回退到 JSoup)
HttpUnit或 HtmlUnit会做的很好,但他们都很难在 android 上运行。
除了 (Android)HttpClient 之外还有其他选择吗(因此我自己做了很多上面的事情)?或者我能以某种方式使用 android webkit/浏览器吗?
提前致谢!
最佳答案
我建议你看看AndroidDriver对于 Selenium 。这似乎是一种使用 Android 测试框架轻松测试 Web 应用程序的直接方法。
您必须使用包含 WebView 的 Activity 才能测试 HTTP/HTTPs 网站。 Driver 是用这个 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);
}
关于android - Android 的 HttpUnit/HtmlUnit 等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9721544/