Test Frameworks: Architecture and Design Patterns
A well-designed test automation framework separates what is tested from how the application is driven: tests describe scenarios, page objects or components hold the selectors and interactions, factories produce test data, and configuration selects the environment. The Page Object Model is the most widely used pattern for this; Screenplay, Factory and Strategy solve the problems it leaves open. This guide explains each layer and pattern, a recommended project structure and the anti-patterns that make frameworks collapse.
- A framework is not a tool: Playwright, Selenium or pytest are the engine; your framework is the structure and conventions you build around them
- Page Object Model: one class per page or component; tests call business methods and keep the assertions
- Screenplay (Serenity BDD, Serenity/JS): actors perform tasks and ask questions, which scales better for large behaviour-driven suites
- Factory and Strategy patterns handle test data and environments; fixtures handle setup and teardown
What is a test automation framework?
A test automation framework is the set of code, conventions and tools that a team uses to write, run and report automated tests consistently. It sits on top of a test runner and a driver library, such as Playwright Test, pytest with Selenium, or JUnit with REST Assured, and adds what those tools do not decide for you: how tests are organised, where selectors live, how data is created, how environments are configured and how results are reported.
What are the layers of a test automation framework?
A maintainable framework separates responsibilities into layers, so a change in one place does not ripple through every test.
- Tests: scenarios and assertions, written in business language.
- Page objects or components: selectors and interactions for each screen or reusable widget.
- Test data: factories, builders and data files.
- Fixtures: setup and teardown, such as logged-in sessions or seeded databases.
- Configuration: URLs, credentials and browser settings per environment.
- Utilities: API clients, custom assertions and helpers.
- Reporting and CI: reports, screenshots, traces and the pipeline that runs everything.
What is the Page Object Model?
The Page Object Model (POM) is a design pattern in which each page or component of the application is represented by a class that holds its locators and exposes its actions as methods. A test calls loginPage.login(user, password) instead of repeating three selectors and a click; when the login form changes, only the LoginPage class is updated.
Two rules keep page objects healthy. First, keep assertions in the tests: the Selenium documentation advises that page objects should not make verifications themselves. Second, model components, not just pages: a header, a date picker or a data table used on many screens deserves its own class. Playwright's documentation describes the same pattern for its tests, with locators defined in the page class constructor.
What is the Screenplay pattern, and when is it better than POM?
The Screenplay pattern models tests around actors who have abilities (browse the web, call an API), perform tasks (place an order) and ask questions (what is the cart total?). It is implemented notably by Serenity BDD in Java and Serenity/JS in JavaScript and TypeScript. It takes more code than POM, but it composes better in large suites and reads naturally in behaviour-driven projects, because tasks are built from smaller interactions instead of growing page classes. For small and medium suites, POM is usually enough.
Which other design patterns are useful in test frameworks?
Beyond page objects, a handful of classic patterns solve recurring test problems.
| Pattern | Problem it solves | Example in tests |
|---|---|---|
| Factory / Builder | Creating valid test objects without repeating every field | UserFactory.create(role="admin") with sensible defaults and Faker values |
| Strategy | Changing behaviour per environment or browser without changing tests | A configuration strategy for local, staging and production-like runs |
| Fixture (dependency injection) | Sharing setup and teardown cleanly | pytest fixtures, Playwright Test fixtures |
| Component object | Reusing widgets that appear on many pages | A DatePicker class used by several page objects |
| Facade | Hiding multi-step setup behind one call | api.createPaidOrder() that chains several requests |
For the data side of the framework, our data-driven testing guide shows how to feed the same test with many data sets.
How should you structure a test automation project?
Mirror the layers in the folders, so anyone can find where a change belongs:
tests/— tests grouped by feature or business domainpages/orcomponents/— page and component objectsfixtures/andfactories/— setup code and test data buildersconfig/— settings per environment, with secrets read from environment variablesutils/— API clients and helpersreports/— generated output, excluded from version control
Should you build your framework on Playwright, Cypress or Selenium?
Build on the tool that matches your team's language and your application's needs; the patterns above work with all three. Playwright supports TypeScript/JavaScript, Python, Java and .NET and includes its own test runner for JavaScript and TypeScript. Cypress is JavaScript/TypeScript only and runs tests inside the browser. Selenium implements the W3C WebDriver standard, supports many languages and relies on a separate runner such as JUnit, TestNG or pytest. Our detailed comparison of Playwright vs Cypress helps with that choice.
What anti-patterns make test frameworks fail?
Most frameworks fail from accumulated shortcuts rather than from a wrong tool choice.
- Selectors in tests: the same selector copied into many files.
- Order-dependent tests: test B only passes if test A ran first.
- Fixed waits:
sleep()calls instead of waiting for a condition. - God page objects: one huge class for the whole application.
- Assertions hidden in helpers: failures that are hard to trace back to the scenario.
- Over-engineering: layers of abstraction that nobody on the team understands.
These rules are detailed in our 10 test automation best practices.
Frequently asked questions
What is the most common design pattern in test automation?
The Page Object Model. Each page or component gets a class that holds its locators and actions, so tests call business methods and a selector change is fixed in one place.
Should page objects contain assertions?
Generally no. The Selenium documentation recommends keeping verifications in the tests, so page objects only describe how to interact with the page and tests decide what is expected.
What is the difference between the Page Object Model and Screenplay?
The Page Object Model organises code around pages. Screenplay organises it around actors, tasks and questions, which takes more code but composes better in large behaviour-driven suites.
Is Playwright a test framework?
Playwright is a browser automation library, and Playwright Test is its test runner for JavaScript and TypeScript. Your team's framework is the structure you build on top: page objects, fixtures, data and configuration.
Should you build your own test automation framework?
Build a thin layer, not a new runner. Use an established runner and driver, and add only the page objects, fixtures, factories and configuration your application needs.
Learn to design test frameworks
At AutomationDataCamp (ADC), the Test Frameworks — Selenium, Playwright, Cypress course (55 h, online) covers advanced Selenium WebDriver, Playwright, Cypress, how to compare and choose a framework, and practical projects to build a robust, scalable one.
View all courses View the 3-month programmePlaywright, Selenium, Cypress and WebdriverIO compared on 12 criteria, first steps with Playwright, GitHub portfolio with a GitHub Actions workflow. Free 25-page PDF, guide in French.
Download the QA Automation Guide 2026Related articles

10 Best Practices for Test Automation
Essential practices for robust and maintainable tests.
Read more : 10 Best Practices for Test Automation
How to Build an Automation Team
Recruiting, training and organisational structure.
Read more : Building an Automation Team