9

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!

LangerJan
  • 165
  • 1
  • 9
  • 1
    This is old but what did you end up using? Can httpunit jar be used directly in the android project? – Fakeer Jun 01 '16 at 18:19
  • At the time I tried it, no. It might have changed since then, though. Sadly, I ended up giving up on Android and switched platforms (made it a web-based application). I tried AndroidDriver, but I couldn't use it in my specific case (can't remember any more why, sorry). – LangerJan Aug 12 '16 at 10:28
  • This is an old question. Any more up to date solutions to this problem? – Dale Jan 29 '22 at 18:10
  • Hello from the past! I gave up android development, good luck on your research. – LangerJan Jan 31 '22 at 09:00

1 Answers1

2

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);
}
Matthew
  • 816
  • 1
  • 7
  • 10
  • Thanks, I will try that. It seems like a bit of an overkill though, since I need to install an seperate apk and communicate with it. Nevertheless it looks like the best solution available :) – LangerJan Mar 16 '12 at 16:48
  • @LangerJan https://github.com/krosenvold/selenium-git-release-candidate/blob/master/android/prebuilt/android-server.apk – m3nda Feb 08 '17 at 03:24
  • Link for AndroidDriver goes to an empty archive, not helpful, which is the reason for downvote. – Dale Dec 11 '21 at 22:50