ArticleslgStudy

computer science

HtmlUnit

HtmlUnit is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand HtmlUnit rather than just read about it. In short: 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.

Key takeaways

  • HtmlUnit belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect HtmlUnit to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of HtmlUnit from memory before moving on to harder problems.

Reference excerpt

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 getPage(url), getLinkWith("Click here"), click() 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

See also

Headless system Web scraping Web testing xUnit

References

Bibliography Beust, Cédric; Suleiman, Hani (15 October 2007). Next Generation Java Testing: TestNG and Advanced Concepts. Pearson Education. ISBN 9780132702270. pp. 339– (subscription required)

Further reading Langer, A. "Extending HtmlUnit for test automatisation of Web applications using AJAX"; Betreuer/in (nen): T. Grechenig, M. Bernhart; 183/1, 2009. (subscription required) Massol, Vincent; Timothy M. O'Brien (2005). Maven: A Developer's Notebook. O'Reilly Media. pp. 83–86. ISBN 978-0-596-55297-8. Tahchiev, Petar; Felipe Leme; Vincent Massol (2010). "12. Presentation Layer Testing". JUnit in Action (2 ed.). Manning. pp. 190–208. ISBN 978-1-935182-02-3. Harold, Elliotte Rusty (16 March 2012). Refactoring HTML. Addison-Wesley Professional. ISBN 9780132701877. Tong, Ka Iok (23 April 2006). Enjoying Web Development with Tapestry. TipTec Development. ISBN 9781411649132. Schalk, Chris; Burns, Ed; Holmes, James (25 August 2006). JavaServer Faces: The Complete Reference. McGraw Hill Professional. ISBN 9780072262407. (subscription required)

External links HtmlUnit

Worked examples

Example 1 — a first encounter with HtmlUnit

Start with the simplest possible case. Write down what HtmlUnit claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to HtmlUnit before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about HtmlUnit ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of HtmlUnit

In research
HtmlUnit appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses HtmlUnit in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
HtmlUnit is common in secondary-school and first-year university syllabi. It links to neighbouring topics Free software programmed in Java, Java (software platform), Load testing tools, so understanding it makes those chapters shorter.
In everyday life
Look for HtmlUnit outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “HtmlUnit” →

How to study HtmlUnit in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what HtmlUnit means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain HtmlUnit out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is HtmlUnit in simple terms?

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.

Why does HtmlUnit matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study HtmlUnit?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on HtmlUnit.

Tags

  • Free software programmed in Java
  • Java (software platform)
  • Load testing tools
  • Software using the Apache license
  • Unit testing frameworks
  • Web browsers
  • Web development
  • Web scraping

Keep exploring