QA Interview Hub · Knowledge base · Quizzes · Українська

Patterns › SOLID, DRY, KISS in tests, and anti-patterns

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.

AntipatternThe damageInstead
God Page Object / God HelperEverything in one place: PR conflicts, unclear responsibilityComponents, small modules by domain
Deep inheritanceA subclass inherits what is not its own and breaks the parent's expectationsComposition
Shared mutable stateTest order becomes a dependency, parallelism breaks itData per test, fixtures
waitForTimeoutSlow and does not guarantee a stateWeb-first assertions, auto-waiting
Assertions in helpersTen silent checks: unclear what failedExpectations in the test
A wrapper over a wrapperHides the API, degrades the traceDirect locators, a wrapper only with value
Logic in a testA non-deterministic pathA fixed precondition
Constants that get mutatedOne test spoils data for othersA factory returning a new object
Abstraction for growthA layer for 20 tests nobody asked forSimple 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

Wrong

A wrapper for its own sake

click(page, selector) adds nothing and hides the options and the call line in the trace.

Right

A wrapper with value

A page method confirmTransfer() combines several actions under a business name in test.step.

Figure 1. A wrapper is justified when it adds value: a business name, several actions, reporting.

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 waitForTimeout with 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.

In an interview. Junior: The antipatterns I name most often are god objects, deep inheritance, shared state between tests and hard timeouts. They are fixed with components, fixtures, isolated data and web-first assertions. Middle/Senior: I explain an antipattern through cause and effect: shared state gives flakes in parallel, a god object gives PR conflicts. I fix them one at a time and measure the effect: run time, the share of flakes. A conscious, limited decision (for example a serial group) I do not count as an antipattern.

More articles in this chapter