chapter eleven

11 Scalable test automation with the Screenplay pattern

 

This chapter covers

  • Actor-centric testing and the Screenplay pattern
  • Modelling users using Screenplay Actors
  • 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 modelling executable specifications. It leverages 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 non-technical audience

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

11.2 Screenplay Fundamentals

11.3 What is an Actor?

11.4 Interactions model how actors interact with the system

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 are how Actors interact with the system

11.6 Writing our own interaction classes

11.7 Questions allow Actor to query the state of the system

11.7.1 Questions query the state of the system

11.7.2 Domain-specific Question classes make our code more readable

11.7.3 Actors can use questions to make assertions

11.8 Tasks model higher-level business actions

11.8.1 Simple tasks improve readability

11.8.2 More complex tasks enhance reusability

11.9 Screenplay and Cucumber

11.9.1 Actors and Casts

11.9.2 The Screenplay Stage

11.9.3 Defining a custom parameter type for actors

11.9.4 Defining persona in Enum values

11.9.5 Screenplay Assertions in Cucumber

11.10 Summary