12 Scalable test automation with the Screenplay Pattern

 

This chapter covers

  • Actor-centric testing and the Screenplay Pattern
  • Interacting with the application with Screenplay Interactions
  • Querying the state of the system with abilities and questions
  • Grouping interactions together to model higher-level business tasks
  • Integrating Screenplay code with Cucumber

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. The Screenplay Pattern is an actor-centered approach to modeling executable specifications. It uses functional composition to help you capture the domain language and represent the various workflows your system needs to support in a way that’s easy to understand by both technical and nontechnical audiences.

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

12.2 Screenplay fundamentals

12.3 What is an actor?

12.4 Actors perform tasks

12.5 Interactions model how actors interact with the system

12.5.1 Actors can perform multiple interactions

12.5.2 Interactions are objects, not methods

12.5.3 Interactions can perform waits as well as actions

12.5.4 Interactions can also interact with REST APIs

12.6 Abilities are how actors interact with the system

12.7 Writing our own interaction classes

12.8 Questions allow an actor to query the state of the system

12.8.1 Questions query the state of the system

12.8.2 Domain-specific Question classes make our code more readable