HtmlUnit

HtmlUnit is a headless web browser written in Java. It allows high-level manipulation of websites from other Java code, including filling and submitting forms and clicking hyperlinks. It also provides access to the structure and the details within received web pages. HtmlUnit emulates parts of browser behaviour including the lower-level aspects of TCP/IP and HTTP. A sequence such as,  ,   allows a user to navigate through hypertext and obtain web pages that include HTML, JavaScript, Ajax and cookies. This headless browser can deal with HTTPS security, basic HTTP authentication, automatic page redirection and other HTTP headers. It allows Java test code to examine returned pages either as text, an XML DOM, or as collections of forms, tables, and links.

The goal is to simulate real browsers; namely Chrome, Firefox and Edge.

The most common use of HtmlUnit is test automation of web pages, but sometimes it can be used for web scraping, or downloading website content.

Benefits

 * Provides high-level API, taking away lower-level details away from the user.
 * Compared to other WebDriver implementations, HtmlUnitDriver is the fastest to implement.
 * It can be configured to simulate a specific browser.

Drawbacks

 * Element layout and rendering can not be tested.
 * The JavaScript support is not complete, which is one of the areas of ongoing enhancements.

Used technologies

 * W3C DOM
 * HTTP connection, using Apache HttpComponents
 * JavaScript, using forked Rhino
 * HTML Parsing, NekoHTML
 * CSS: using CSS Parser
 * XPath support, using Xalan

Libraries using HtmlUnit

 * Selenium WebDriver
 * Spring MVC Test Framework
 * Google Web Toolkit tests
 * WebTest
 * Wetator