Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpUnit/HtmlUnit equivalent for android

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!

like image 232
LangerJan Avatar asked Mar 15 '12 14:03

LangerJan


People also ask

What is HtmlUnit driver in selenium?

HtmlUnitDriver is headless driver providing non-GUI implementation of Selenium WebDriver. It is based on HtmlUnit, fastest and light-weight browser implemented in Java.

Which driver is faster in selenium?

HTML UnitDriver is the most light weight and fastest implementation headless browser for of WebDriver. It is based on HtmlUnit. It is known as Headless Browser Driver.

Which of the following selenium codes is used to enable Javascript by using HtmlUnitDriver?

WebDriver driver = new HtmlUnitDriver(); driver. get(url); javascript.


1 Answers

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);
}
like image 181
Matthew Avatar answered Oct 12 '22 23:10

Matthew