What is the Screenplay Pattern?
This is part 1 of 3 in a series about using the Screenplay pattern in Swift.
Part 2: Screenplay Entities with XCTest and Swift Part 3: Writing Screenplay Tests in Swift
The Screenplay pattern for UI testing is an 'upgrade' to the Page Object pattern.
The Page Object pattern is a great UI testing pattern which provides a simple, easy-to-understand architecture for your UI testing code. It has a low barrier to entry, and is well-suited to those without much programming experience. Unfortunately, to make the Page Object pattern accessible to new programmers, it does make some sacrifices with regards to scalability.
The Screenplay pattern aims to solve the Page Object pattern's lack of scalability by adhering to SOLID principles.
It should be noted that by improving on the scalability of the Page Object pattern, the barrier to entry does become higher in terms of understanding required. Therefore, when choosing between the Page Object and Screeplay patterns, you should decide whether accessibility or scalability matter more to you.
In the Screenplay pattern, the responsibilities which would have been taken on by a page object in the Page Object pattrn are split up into multiple objects, in order to satisfy the Single Responsibility principle (the S in SOLID). These responsibilities are:
Encapsulating element location details
Encapsulating interaction implementation details
Providing a behavioural interface for user actions
Providing a state inquiry interface for the application under test
Depending on your UI testing requirements, there may be an additional responsibility; holding a reference to the instance of the application under test. This responsibility is only useful if you are testing more than one application instance at once. For now, let's assume you're just testing a single application at a time.
Screenplay Architecture
Element Locators encapsulate element location details.
Actions encapsulate interaction implementation details.
Tasks provide a behavioural interface for user actions.
Questions handle state enquiries.
Actors facilitate the execution of Actions and answering of Questions.
In part 2, you'll see how each of these entities can be implemented, and how they interact with each other.











