15 Presentation-layer testing

 

This chapter covers

  • Developing HtmlUnit tests
  • Developing Selenium tests
  • Comparing HtmlUnit and Selenium

If debugging is the process of removing software bugs, then programming must be the process of putting them in.

--Edsger Dijkstra

Simply stated, presentation-layer testing involves finding bugs in the graphical user interface (GUI) of an application. Finding errors here is as important as finding errors in other application tiers. A bad user experience can lose a customer or discourage a web surfer from visiting your site again. Furthermore, bugs in the user interface can cause other parts of the application to malfunction.

Due to its nature and user interaction, GUI testing presents unique challenges and requires its own set of tools and techniques. This chapter will cover the testing of web application user interfaces. We address what can be objectively--that is, programmatically--asserted about the GUI (by writing explicit Java code). Subjective elements like fonts, colors, and layout are outside the scope of this discussion.

Testing interaction with websites can be challenging from the point of view of stability. If the website content changes over time, or if you encounter problems with your internet connection, this kind of test may occasionally or permanently fail. The tests presented in this chapter have been designed to have high long-term stability by accessing known websites with less probability of changing in the near future.

15.1 Choosing a testing framework

15.2 Introducing HtmlUnit

15.2.1 A live example

15.3 Writing HtmlUnit tests

15.3.1 HTML assertions

15.3.2 Testing for a specific web browser

15.3.3 Testing more than one web browser

15.3.4 Creating standalone tests

15.3.5 Testing forms

15.3.6 Testing JavaScript

15.4 Introducing Selenium

15.5 Writing Selenium tests