Screenplay Pattern

How Screenplay differs from the Page Object Model and when it makes automated test architecture easier to maintain.

Updated:

Contents

The Screenplay Pattern organizes automated tests around an actor and a goal. Instead of centering on pages, a scenario describes what a customer, manager, or administrator does, which capabilities they use, and what they observe. This supports domain-focused language when journeys cross several screens or protocols.

The pattern is especially visible in large acceptance suites. Checkout may use a browser, user setup an API, and event verification a separate client. Screenplay separates those mechanisms while keeping the top-level goal clear. The cost is additional concepts and team discipline.

The core concepts

An Actor participates in a scenario, such as a customer named Anna. An Ability is an available technical capability, such as browsing or calling an API. A Task expresses a business goal, such as placing an order. An Interaction is a specific action, such as clicking a button. A Question retrieves an observable answer, such as the total amount.

Names and APIs vary by implementation. The concepts do not require a particular library, but a framework can provide composition, reporting, and runner integration. Choose a language and implementation, then follow its documentation rather than mixing examples from different ecosystems.

How scenario structure changes

A Page Object scenario often interacts with cart, payment, and confirmation pages. A Screenplay scenario asks an actor to place an order with delivery and asks for the order's status. Element objects can remain inside low-level interactions; the approaches can coexist.

Separate intent from mechanism. A button change should affect an interaction, a business-process change a task, and an authentication change an ability or setup. If every change requires rewriting every layer, the separation exists only on paper.

Practical example: approving a return

In a training store, a customer requests a return and a manager approves it. The customer can access only their own order; the manager works with a request queue. Use an isolated eligible order and two test users. No real refund occurs in this exercise.

The scenario has two goals: Anna submits a request and Boris approves it. After submission, expect requested status and visibility in the manager's queue. After approval, expect approved status and customer confirmation. Attempted approval by the customer belongs in a separate negative example.

Breaking down tasks

The submit-request task receives an order ID and reason; it should not select a random order itself. Internally, it opens the specified record, enters the reason, and submits. The approve task receives the created request's ID, preserving an explicit connection between the actors' actions.

The request-status question reads state in a way that matches the test's goal. A screen test should read the UI; a cross-service process test may observe the API. Replacing a UI read with an API read must not silently remove verification of the user-visible result.

Multiple actors and isolation

Each actor needs an independent session and controlled role. Two names in a report do not provide isolation if both share a browser context and cookie. Use separate contexts for browser scenarios and separate client credentials for API scenarios.

Associate data with the particular run too. The manager's task should not take the first request, because another parallel test might create it. Passing IDs explicitly and checking ownership makes multiuser scenarios reproducible and helps reveal access defects.

Handling assertions

A Question provides a fact, and an expectation compares it with a requirement. For example, request status should be approved. The approve action should not always assert the complete result internally, because it may also be used to test a prohibited transition or unavailable dependency.

Failure messages should retain the actor and business goal. “Expected approved, got requested for request return-42” is more useful than an exception inside a generic click helper. Clear reporting follows from clear tasks.

Where Screenplay helps

The approach helps when goals recur across journeys, several roles participate, and the suite needs a readable business narrative. Adding a product or changing its quantity may appear in payment, reservation, and return flows. A shared task reduces repetition without tying the top-level scenario to one screen.

Reuse must preserve meaning. A universal “execute step with parameters” task becomes an interpreter and loses domain language. Parameters should describe goal data rather than hidden browser commands.

When the cost is not justified

For a few simple screens, a small Page Object may be clearer. Screenplay adds interfaces, classes, and composition rules the team must learn. If team members cannot diagnose a failure independently, the architecture increases dependence on its author.

Pilot one real journey. Compare changing a locator, adding a negative case, and having a new colleague read the report. Success means less repetition and clearer diagnosis, rather than a larger number of Task classes.

Common adoption problems

Creating a task for every click turns a business scenario into a long technical list. Creating one giant task for the entire process hides data, roles, and checks. Both extremes undermine clear boundaries.

Avoid storing all actors' mutable state in a shared singleton. Keep secrets out of task descriptions that appear in reports. Renaming page methods as tasks alone cannot improve a suite; reconsider component responsibilities.

Key takeaways for QA

Screenplay separates roles, abilities, goals, and observations. It is especially useful for composite scenarios and multiple participants when the team can maintain clear domain language.

Start with a concrete problem: repeated business actions, confusing roles, or poor readability. Then establish whether the model solves it in practice. Architectural maturity is reflected in understandable changes and failures, rather than the complexity of the pattern.

Further reading