Typical antipatterns in frameworks
A framework antipattern is a solution that looks reasonable and later does harm. Examples: god objects, deep inheritance, shared mutable state, waitForTimeout, assertions in helpers. They boil down to structure, state, time and clarity. They are named through cause and effect, fixed one at a time and the effect measured. A deliberate, limited, documented decision, such as a serial group, is not an antipattern.
Patterns · Antipatterns
The framework grew: runs are slow and flakes multiply. What is wrong in its architecture?
An antipattern is a typical solution that looks reasonable and later does harm. Test frameworks have few of them, and they repeat from project to project, so it is worth being able to name them, explain the damage and propose a replacement. An interviewer usually expects not a list of terms but an explanation of how they show up (flakes, slow runs, painful PRs) and what is done about them.
How it works and why. All antipatterns boil down to four causes. Structure: god objects, deep inheritance, wrappers over wrappers. State: shared variables and constants, test order as a dependency; in Playwright tests are isolated because they run in parallel and may restart, so a dependency on order will not survive. Time: hard waits with waitForTimeout instead of web-first assertions and auto-waiting. Clarity: assertions without purpose in helpers, logic in tests, abstraction for growth. The table puts them together.
| Antipattern | The damage | Instead |
|---|---|---|
| God Page Object / God Helper | Everything in one place: PR conflicts, unclear responsibility | Components, small modules by domain |
| Deep inheritance | A subclass inherits what is not its own and breaks the parent's expectations | Composition |
| Shared mutable state | Test order becomes a dependency, parallelism breaks it | Data per test, fixtures |
| waitForTimeout | Slow and does not guarantee a state | Web-first assertions, auto-waiting |
| Assertions in helpers | Ten silent checks: unclear what failed | Expectations in the test |
| A wrapper over a wrapper | Hides the API, degrades the trace | Direct locators, a wrapper only with value |
| Logic in a test | A non-deterministic path | A fixed precondition |
| Constants that get mutated | One test spoils data for others | A factory returning a new object |
| Abstraction for growth | A layer for 20 tests nobody asked for | Simple code first, the rule of three |
Example 1: a wrapper over a wrapper. A custom click() that calls locator.click() with no added value hides API capabilities (options, force, timeout) and degrades the trace:
// a wrapper with no value: hides locator.click() and its options
async function click(page: Page, selector: string) {
await page.locator(selector).click();
}
// a direct call: all the options, the trace shows the real line
await page.getByRole('button', { name: 'Confirm' }).click({ timeout: 5_000 });
Example 2: constants that get mutated. One test changes a shared constant, and the next ones get a spoiled state. A dependency on test order arrives quietly:
// a shared constant: a test changes it, the next ones see the change
export const USER = { email: 'qa@example.com', role: 'user' };
test('promotes the user', async () => {
USER.role = 'admin';
});
// a function: every call gives a new object
export const makeUser = () => ({ email: 'qa@example.com', role: 'user' });
A wrapper: when it is real
A wrapper for its own sake
click(page, selector) adds nothing and hides the options and the call line in the trace.
A wrapper with value
A page method confirmTransfer() combines several actions under a business name in test.step.
Limits and alternatives. An antipattern is not always an error in every context: waitForTimeout is sometimes left deliberately for debugging, and shared state in a serial group is a conscious agreement. The difference is that the decision is explicit, limited and written down, not an accidental consequence. And conversely, over-fighting antipatterns also hurts: rewriting working code because of a term is not worth it while there is no real pain.
How to talk about it at an interview. Do not just list them but show the cause-and-effect chain and the measure. A hypothetical example: a base class with sixty methods is cut into components (a header, a table), login is moved to storageState, and the effect is measured before and after: run time, the number of PR conflicts, the share of flakes.
Common mistakes.
- Only listing terms without explaining the damage: the answer sounds memorised.
- Treating
waitForTimeoutwith a larger timeout: that hides the symptom while the race remains. - Cutting a god object into several equally bloated ones: the structure changed, the problem stayed.
- Seeing an antipattern where the decision is conscious and limited, and rewriting for no benefit.
- Fixing all antipatterns in one big PR: risky and hard to review; better one at a time, measuring the effect.
Check yourself
Tests pass one by one but with --workers=4 some fail. Which two antipatterns from the table to check first?
Answer
Shared mutable state (module variables, constants that tests mutate) and dependency on execution order. In a parallel run tests land in different workers where this data is separate or the order is different.
A colleague added a utility click(page, selector) and explained it is a single point of change. Is it an antipattern?
Answer
Yes, if it only calls locator.click(): there is no value, and the options and a clear line in the trace are lost. A wrapper is justified when it adds value: a business name, several actions, test.step.