HttpUnit/HtmlUnit equivalent for android

可紊 提交于 2019-11-26 18:26:41

问题


I'm looking for a browser-simulating library on android, which handles things like

  • loading a website (http/https)
  • Redirections: HTTP (3xx Status Codes), JavaScript, HMTL tags
  • filling out html-forms
  • easy html parsing (could fall back to JSoup for that one)

HttpUnit or HtmlUnit would do just fine, but both of them are a pain to get running on android.

Is there any other option other than (Android)HttpClient (and therefore doing lots of the above on my own)? Or can I somehow get use of the android webkit/browser?

Thanks in advance!


回答1:


I would recommend you to have a look at AndroidDriver for selenium. It seems to be a straightforward approach to easy test WebApplications with the Android Testing Framework.

You must use an Activity that includes a WebView in order to test HTTP/HTTPs websites. The Driver is instanciated with this Activity:

WebDriver driver = new AndroidWebDriver(getActivity());

Here is a sample test, quoted from the link above:

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


来源:https://stackoverflow.com/questions/9721544/httpunit-htmlunit-equivalent-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!