chapter nine

9 Automating acceptance criteria for the UI layer

 

This chapter covers

  • Why and when you should write automated UI tests
  • Using tools like Selenium WebDriver in Java to automate web tests
  • Finding and interacting with page elements in your tests
  • Design patterns to write more maintainable web tests

In the previous chapter, you learned how using a layered approach to automated acceptance testing helps make your tests clearer, more robust, and more maintainable. We discussed the three broad layers used in well-designed automated acceptance tests: the Business Rules layer, the Business Flow layer, and the Technical layer. In the following few chapters, we’ll focus on approaches and tools that can be used to implement the Technical layer, starting with the user interface.

In this chapter we’ll discuss techniques to automate UI tests for web-based applications. Users interact with an application through its user interface, and in modern web applications, the UI implementation plays a major role in the overall user experience. The screenshots from automated web tests can be a valuable aid for testers, and they’re also a great way to provide illustrated documentation describing how the application behaves.

We’ll look at automated web testing from several perspectives, as well as a few popular automation libraries used for web testing:

9.1 When and how should you test the UI?

9.2 Where does UI testing fit in your test automation strategy?

9.2.1 Which scenarios should be implemented as UI tests?

9.2.2 Illustrating user journeys

9.2.3 Illustrating business logic in the user interface

9.2.4 Documenting and verifying screen-specific business logic

9.2.5 Showing how information is rendered in the user interface

9.3 Automating web-based acceptance criteria using Selenium WebDriver

9.3.1 Getting started with WebDriver in Java

9.3.2 Setting up a WebDriver driver

9.3.3 Integrating WebDriver with Cucumber

9.3.4 Sharing WebDriver instances between step definition classes

9.3.5 Interacting with the web page

9.3.6 How to locate elements on a page

9.3.7 Interacting with web elements

9.3.8 Working with modern UI library components

9.3.9 Working with asynchronous pages and testing AJAX applications

9.4 Test-friendly web applications

9.5 Next Steps

9.6 Summary