Chapter 14. End-to-End Web Testing

One of the trickier types of automated testing is checking a web application via the browser. Differences in rendering in different browsers, frequent upgrades, and—more than anything—speed can be major issues when it comes to testing in a browser. Web UIs can change rapidly and break tests that are too tightly coupled to the fine-grained structure of the page. It’s very important to develop a good abstraction so that the details of HTML structure, such as hierarchies of elements and particular classes and IDs, are not liberally spread throughout your test suite making it very difficult to change the structure without considerable rework repairing tests. If you’re using a continuous integration server, it can be difficult to make browser-based tests work when the server probably does not have a display attached and typically might not even have a graphical environment at all.

In this chapter, we’ll develop some in-browser tests using Spock and a library called Geb. We’ll build and test a web frontend for the Squawker application. As we do this, we’ll examine how to build a page model abstraction that decouples tests from the DOM structure of the web pages.

Geb

Geb (pronounced “jeb”) is a browser automation API that wraps around Selenium. With Geb, Java code can issue commands to a browser and interact with pages. Although you can use it for scripting purposes, the primary use of Geb is to write functional or end-to-end tests for web applications. ...

Get Spock: Up and Running now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.