chapter eleven

11 Scalable test automation with the Screenplay pattern

 

This chapter covers

  • Actor-centric testing and the Screenplay pattern
  • Screenplay Actors
  • Other related stuff

As your test automation framework grows, you quickly realize that your biggest problem isn’t knowing how to automate each new scenario; it’s being able to add these new scenarios while at the same time keeping your code base simple and maintainable. As your test suite interacts with different UI components, APIs, databases and more, keeping your code simple and consistent can be harder and harder to do.

The Screenplay Pattern, which we will be covering in this chapter, is an approach to keeping this complexity under control as our frameworks grow.

Let’s start with a quick example of how the Screenplay pattern can help us write cleaner, more maintainable test automation code.

11.1 What is the Screenplay Pattern and why do we need it?

In the previous couple of chapters, we’ve seen a few other approaches to help keep your test automation code clean. Page Objects are one example. We’ve seen how the Page Object Model can help to separate low-level WebDriver code from your step definition code, which can reduce duplication and simplify your step definition code.

11.2 Screenplay Fundamentals

11.3 Actors

11.4 Interactions

11.4.1 Actors can perform multiple interactions

11.4.2 Interactions are objects, not methods

11.4.3 Interactions can perform waits as well as actions

11.4.4 Interactions can also interact with REST APIs

11.5 Abilities

11.5.1 Writing our own interaction classes

11.6 Questions

11.6.1 Questions help us query the state of the system

11.6.2 Domain-specific Question classes make our code more readable

11.6.3 Actors can use questions to make assertions

11.7 Tasks

11.7.1 Simple tasks improve readability

11.7.2 More complex tasks enhance reusability

11.8 Screenplay and Cucumber

11.8.1 Actors and Casts

11.8.2 The Screenplay Stage

11.8.3 Defining actors as Enums

11.8.4 Screenplay Assertions in Cucumber

11.9 Summary