Chapter 15: Mise-en-scène patterns for layering the automation codebase
The introduction explains why a growing scenario-automation codebase needs clear responsibilities and why the WIMP team adds some REST API scenarios to its direct-code tests.
After this chapter you will be able to
- Separation of automation responsibilities. Explain why a growing automation codebase should identify distinct responsibilities and implement them in separate parts, rather than relying only on small refactorings.
- Direct and outer interface coverage. Explain why the WIMP team supplements scenarios that call production service methods directly with scenarios run through the REST API.
- Dedicated application host. Explain why automation through an outer interface needs a running application host and why that host should be dedicated to the tests.
- External and self-hosting trade-offs. Distinguish externally hosted applications from self-hosted ones in terms of what test code can access and how easily it can isolate scenarios.
- Per-scenario host and requests. Describe how the WIMP team starts a fresh host for each scenario and how its step definitions reach that self-hosted application.
- Testing and automation concerns. Distinguish the testing concern of turning specification statements into testable actions from the automation concern of exercising the system under test, and describe how they form layers beneath the specification.
- Thin reusable step definitions. Explain why step definitions should make testing decisions and delegate application actions to reusable drivers rather than call other step definitions.
- Driver encapsulation boundary. Describe how the authentication API driver takes responsibility for login automation and why its interface should hide technical details from step definitions.
- Three automation code layers. Explain how the Infrastructure Layer pattern separates testing concerns, automation actions, and infrastructure details, and why this makes outer-interface automation easier to maintain.
- Repeated concerns across driver methods. Explain why the WIMP team treats driver methods as test actions rather than adding logging and timing code to every method.
- Shared action base class. Describe how the team's test action base class separates shared functionality from the action's own work, including its treatment of calls with and without a return payload.
- Lambda actions and concrete classes. Distinguish when the team uses a reusable LambdaAction from when a dedicated concrete test action class may be clearer, and explain the common benefit.
- Attempted action outcome timing. Explain why an exceptional-case When step captures an action’s outcome rather than failing immediately, and why its wording says “attempt” or “try.”
- Captured action result. Trace how AttemptExecute returns an action result and how a subsequent step uses it to validate behavior. Explain why this replaces repeated try-catch code in step definitions.
- Default failure behavior. Distinguish ordinary action execution from opt-in attempt execution, including how Given steps and happy-path When steps should respond to action failure.
- Polymorphic Driver Structure. Describe how the Polymorphic Driver pattern separates a test driver's logical actions from the application interface used to carry them out.
- Configuration Based Driver Selection. Trace how step definitions and dependency injection support selecting a driver implementation for a test run.
- Replaceable external dependencies. Explain why a test might replace a real external service with a stub, using the time-dependent scenario as an example.
- Stub selection by interface. Distinguish how the application is configured to use a stub when tests invoke it through an inner interface versus an outer interface.
- Shared stub time service. Trace how the example makes a controllable time service available to both the step automation and the application.
- Maintainable Automation at Scale. Explain why the chapter’s patterns matter for larger BDD automation codebases, particularly those automating applications with multiple interfaces and external dependencies.
- Ports and adapters boundaries. Explain how hexagonal architecture separates core business logic from external dependencies, and distinguish ports from adapters.
- Configurable automation connections. Describe how inbound and outbound ports give BDD automation choices about invoking the application and using real or stubbed external services.
- Screenplay’s five concepts. Explain how actors, abilities, tasks, interactions, and questions fit together in a Screenplay test.
- Screenplay and BDD code. Describe how the Screenplay concepts correspond to BDD scenario steps and the automation layers discussed in this chapter.
What it builds on
- Test-code quality (chapter 12) · The importance of test-code quality in scenario automation.
- Automation strategies (chapter 12) · Earlier discussion of automation strategies.
- Isolated scenarios (chapter 12) · The Isolated scenario principle provides the reason to value a separate test environment.
- Hooks (chapter 12) · Hooks run around scenario execution.
- Shareable Scenario Context pattern: sharing data between step definitions in different classes (chapter 13) · Shareable scenario context makes data available across step definitions.
- Shared understanding (chapter 6) · BDD scenarios express a shared, business-readable understanding of behavior.
- Step definitions (chapter 12) · Step definitions connect scenario steps to automation code.
- Keep your scenarios BRIEF (chapter 7) · The BRIEF principles for readable scenarios.
Section by section
Introduction
The introduction explains why a growing scenario-automation codebase needs clear responsibilities and why the WIMP team adds some REST API scenarios to its direct-code tests.
- Separation of automation responsibilities: Explain why a growing automation codebase should identify distinct responsibilities and implement them in separate parts, rather than relying only on small refactorings.
Why it matters: Clear responsibilities make an expanding automation suite easier to maintain. - Direct and outer interface coverage: Explain why the WIMP team supplements scenarios that call production service methods directly with scenarios run through the REST API.
Why it matters: The choice of automation interface affects both feedback speed and confidence in how users or clients reach the application.
Key terms: responsibilities, step definitions, test-code quality, service class methods, outer layer, REST API interface, fast feedback
15.1 Automating though an outer interface
This section explains how automated scenarios can call an application through its REST API, how to host and reach the application during tests, and when asynchronous test code is useful.
- Dedicated application host: Explain why automation through an outer interface needs a running application host and why that host should be dedicated to the tests.
Why it matters: A dedicated host makes API-based scenarios more reliable and easier to configure. - External and self-hosting trade-offs: Distinguish externally hosted applications from self-hosted ones in terms of what test code can access and how easily it can isolate scenarios.
Why it matters: The hosting choice affects both test customization and scenario isolation. - Per-scenario host and requests: Describe how the WIMP team starts a fresh host for each scenario and how its step definitions reach that self-hosted application.
Why it matters: A step definition needs a way to reach the particular host created for its scenario. - Asynchronous calls in test automation: Justify choosing synchronous or asynchronous step definitions for functional test automation, including the choice made in the examples.
Why it matters: It keeps the team from treating async as mandatory when choosing how to write step definitions.
Key terms: outer interface, application host, dedicated application host, externally hosted application, self-hosting, public API, Isolated scenario principle, hooks, WimpAppHost, AppHostingContext
15.2 Test Driver pattern: separating automation logic
This section explains how Test Drivers separate automation details from step definitions so scenarios can reuse application interactions without exposing interface-specific code.
- Testing and automation concerns: Distinguish the testing concern of turning specification statements into testable actions from the automation concern of exercising the system under test, and describe how they form layers beneath the specification.
Why it matters: This distinction helps the reader decide where automation code belongs. - Thin reusable step definitions: Explain why step definitions should make testing decisions and delegate application actions to reusable drivers rather than call other step definitions.
Why it matters: Reusable drivers let different steps share application actions without coupling their testing decisions. - Driver encapsulation boundary: Describe how the authentication API driver takes responsibility for login automation and why its interface should hide technical details from step definitions.
Why it matters: Hiding interface details means a technical change need not force changes across step definitions. - Test Driver applicability: Describe where Test Drivers can be used beyond an external UI or API and when the pattern is particularly useful.
Why it matters: The pattern applies wherever repeated technical interactions need to be kept out of step definitions.
Key terms: testing concern, automation concern, system-under-test, layered automation code architecture, step definitions, drivers, testing decisions, automation responsibility, Test Driver, AuthenticationApiDriver
15.3 Infrastructure Layer pattern: separate infrastructure code
This section shows how the Infrastructure Layer pattern moves repeated technical plumbing out of test drivers, leaving each layer with a clearer responsibility.
- Three automation code layers: Explain how the Infrastructure Layer pattern separates testing concerns, automation actions, and infrastructure details, and why this makes outer-interface automation easier to maintain.
Why it matters: Keeping technical plumbing out of drivers makes automation code clearer and easier to maintain. - Shared REST request helpers: Describe how the WIMP team centralized repeated REST request handling and what their two helper methods cover.
Why it matters: Shared helpers remove repetitive REST plumbing from individual driver methods. - Application-specific infrastructure design: Explain why infrastructure helpers are tailored to the application rather than built as a general-purpose interface library, and describe what remains in the drivers.
Why it matters: Tailoring helpers to the application's actual needs reduces plumbing without hiding what each driver action does.
Key terms: Infrastructure Layer pattern, test layer, automation layer, infrastructure layer, drivers, RestApiContext, GetRequest, ProcessRequest, bearer token, status code
15.4 Test Action pattern: simplified management of test actions
The section shows how the Test Action pattern separates repeated logging and timing from REST API actions while keeping actions easy to use and reuse.
- Repeated concerns across driver methods: Explain why the WIMP team treats driver methods as test actions rather than adding logging and timing code to every method.
Why it matters: It explains the duplication the pattern is meant to remove. - Shared action base class: Describe how the team's test action base class separates shared functionality from the action's own work, including its treatment of calls with and without a return payload.
Why it matters: One shared implementation can provide functionality for every action without absorbing each action's specific logic. - Actions through drivers and steps: Describe how drivers expose test actions to step definitions and how a step definition can use an action when it needs to inspect a result.
Why it matters: It connects the action abstraction to the drivers and step definitions that use it. - Lambda actions and concrete classes: Distinguish when the team uses a reusable LambdaAction from when a dedicated concrete test action class may be clearer, and explain the common benefit.
Why it matters: The team can avoid boilerplate for small actions without giving up a clearer class for complex ones.
Key terms: Test Driver, test action, cross-cutting, non-functional concerns, test action base class, DoExecute, TResult, VoidReturn, driver, step definitions, LambdaAction
15.5 Attempt Action pattern: when failure is allowed
This section explains how the Attempt Action pattern captures an action’s outcome for a later Then step to assess, while ordinary action execution still fails immediately.
- Attempted action outcome timing: Explain why an exceptional-case When step captures an action’s outcome rather than failing immediately, and why its wording says “attempt” or “try.”
Why it matters: The scenario can verify an expected failure without treating that failure as a failed test. - Captured action result: Trace how AttemptExecute returns an action result and how a subsequent step uses it to validate behavior. Explain why this replaces repeated try-catch code in step definitions.
Why it matters: One result-handling path makes exceptional-case step definitions simpler and less error-prone. - Default failure behavior: Distinguish ordinary action execution from opt-in attempt execution, including how Given steps and happy-path When steps should respond to action failure.
Why it matters: Failing by default prevents an unexpected broken action from being mistaken for a valid scenario outcome. - Atomic result assertions: Explain why the result object gains specific assertion methods for checking an attempted action’s outcome.
Why it matters: A single focused assertion better reflects the outcome the scenario specifies.
Key terms: Attempt Action, When, Then, exceptional cases, negative scenarios, AttemptExecute, TestAction, TestActionResult, try-catch, happy path
15.6 Polymorphic Driver pattern: reuse driver interfaces
This section explains how technology-agnostic test drivers let one set of BDD scenarios run through different application interfaces, with drivers selected per test run or per scenario.
- Interface Independent Scenarios: Explain why the same BDD scenarios can be automated through different application interfaces when they describe business behavior rather than technical details.
Why it matters: Keeping technical interface details out of scenarios makes them reusable across automation strategies. - Polymorphic Driver Structure: Describe how the Polymorphic Driver pattern separates a test driver's logical actions from the application interface used to carry them out.
Why it matters: One automation codebase can share scenarios and automation code while exercising different parts of the application. - Configuration Based Driver Selection: Trace how step definitions and dependency injection support selecting a driver implementation for a test run.
Why it matters: Configuration lets a team choose faster or broader test runs without rewriting its scenarios or step definitions. - Scenario Specific Driver Selection: Explain how tags can select drivers for individual scenarios and why a team might use that instead of running every scenario through the UI.
Why it matters: A small selection of UI scenarios can provide regular confidence without slowing every build as much as a full UI run.
Key terms: BRIEF principles, business language, application interface, Polymorphic Driver pattern, Test Driver interfaces, test actions, automation interface, step definitions, IAuthenticationDriver, dependency injection
15.7 Stub Dependency pattern: stubbing an external service
This section explains how the Stub Dependency pattern makes slow or hard-to-control external services replaceable during scenario automation, using a time service as its example.
- Replaceable external dependencies: Explain why a test might replace a real external service with a stub, using the time-dependent scenario as an example.
Why it matters: This is the problem the pattern is meant to solve. - Stub selection by interface: Distinguish how the application is configured to use a stub when tests invoke it through an inner interface versus an outer interface.
Why it matters: Configuring the wrong DI container will not replace the service the application actually uses. - Shared stub time service: Trace how the example makes a controllable time service available to both the step automation and the application.
Why it matters: Setting a stub's time helps only if the application reads and subscribes to that stub. - Real dependency verification: Justify running tests regularly against the real dependency even when developer and CI builds use a stub.
Why it matters: Fast feedback is useful only if it remains trustworthy.
Key terms: Stub Dependency pattern, external service, ITimeService, stub, DI configuration, inner interface, outer interface, application framework, StubTimeService, driver
15.8 Related patterns
This section connects the chapter’s automation patterns to the need for maintainable BDD automation in real-world applications and introduces two related patterns for later discussion.
- Maintainable Automation at Scale: Explain why the chapter’s patterns matter for larger BDD automation codebases, particularly those automating applications with multiple interfaces and external dependencies.
Why it matters: This explains the practical problem that motivates layering automation code.
Key terms: BDD automation codebases, multiple interfaces, external dependencies
15.8.1 Hexagonal Architecture pattern
This section explains how hexagonal architecture separates business logic from external services through ports and adapters, making BDD automation easier to configure and test.
- Ports and adapters boundaries: Explain how hexagonal architecture separates core business logic from external dependencies, and distinguish ports from adapters.
Why it matters: The distinction explains how an application can change its external connections without defining its business logic in terms of a particular service. - Configurable automation connections: Describe how inbound and outbound ports give BDD automation choices about invoking the application and using real or stubbed external services.
Why it matters: These choices let automation exercise different ways into the application while controlling its external dependencies.
Key terms: Hexagonal Architecture, Ports and Adapters, core business logic, ports, adapters, inbound ports, outbound ports, Polymorphic Driver pattern, Stub Dependencies pattern, stub implementation
15.8.2 Screenplay pattern
The section explains Screenplay’s actor-centered model for automated tests, relates its concepts to BDD automation code, and identifies when its stronger actor model is useful.
- Screenplay’s five concepts: Explain how actors, abilities, tasks, interactions, and questions fit together in a Screenplay test.
Why it matters: These concepts give you a way to describe test automation in terms of what an actor is trying to accomplish. - Screenplay and BDD code: Describe how the Screenplay concepts correspond to BDD scenario steps and the automation layers discussed in this chapter.
Why it matters: The correspondences let you recognize Screenplay ideas in a BDD automation codebase you may already have. - Value of a stronger actor model: Justify when Screenplay’s actor model can add value to BDD automation, even when the existing patterns are similar.
Why it matters: It helps a team judge when explicitly modeling actors would clarify its tests.
Key terms: actor, ability, tasks, interactions, questions, scenario steps, step definitions, scenario context, driver methods, test actions
15.9 Summary
Where this is used later
- Scenario Resource pattern: managing test resources (chapter 16) · Managing the application host as a test resource builds on why tests need one.
- Test Log pattern: recording scenario execution details (chapter 19) · The Test Action pattern's shared action infrastructure.
- Corroboration Check pattern: monitoring the application’s health indicators (chapter 19) · negative scenarios using the Attempt Action pattern
- Test Configuration (chapter 20) · The Polymorphic Driver pattern is cited as an earlier use of test parameters.
- Parameterized Execution pattern: extend the coverage of BDD scenarios (chapter 20) · Parameterized Execution discusses other approaches to varying test execution.
- (chapter intro) (chapter 18) · The use of stubs for dependencies during scenario automation.
- (chapter intro) (chapter 20) · Provides the earlier context of using a stub for an external dependency.
- Synchronous Testing pattern: turning the asynchronous behavior to synchronous for testing (chapter 21) · The WIMP stub time service is an example of the Stub Dependency pattern.
Concepts explained in this chapter
- test driver patternA pattern that provides an outcome-oriented interface to test automation while encapsulating the technical details of interacting with an application component.
- polymorphic driver patternA BDD automation pattern that runs the same scenarios against different application interfaces by selecting interchangeable test-driver implementations.
- stub dependency patternA testing pattern that replaces a slow or hard-to-control dependency with a controllable test substitute.
- attempt action patternA testing pattern that separates initiating an action from verifying its expected outcome, including an expected failure.
- infrastructure layerThe automation-solution layer containing helper methods for interacting with underlying software infrastructure.
- layered automation code architectureAn architecture that separates the testing concern from the automation concern into distinct layers.
- test action patternA pattern in which test-action infrastructure interacts with an application and captures functional failures and health incidents.
- driver interfaceA contract defining the actions and data exchange that automation code expects from a test driver, independently of the application interface used to perform them.
- test actionA unit of automation logic that performs an operation against the system under test as part of a behavioral test.
- screenplay patternThe Screenplay pattern is a test-automation design pattern that models actors, abilities, tasks, and questions to express interactions with a system.
- hexagonal architectureHexagonal architecture is a software architecture pattern that isolates core application logic from external systems through ports and adapters.
- cross-cutting concernA concern, such as logging or timing, that affects multiple parts of a software system rather than one isolated operation.
- stubA test double that substitutes for a real dependency and provides predetermined behavior or responses.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
