Test automation and the SDET
Automation is a product with users, owners and a defect rate: decide what to automate, at which level, in which framework, who fixes it when it breaks, and how much flake you will tolerate
A browser test in the merge-gating suite fails about once in every 40 runs and passes on rerun. The team is annoyed. What do you do first?
Test automation is code that checks other code. That sentence is obvious and most teams forget it. They treat the suite as a by-product of testing, something the QA engineer accumulates, rather than a product with users (every engineer who merges), a defect rate (flake), a maintenance cost and an owner. This chapter is about building the suite as that product: what to automate, at which level, in which framework, who fixes it, and how much flake you will accept before you stop and fix it.
The SDET and what the title means
SDET stands for software development engineer in test. The title is usually traced to Microsoft, and it names a real distinction: a tester who writes production-quality code, as opposed to a tester who executes cases or a developer who writes tests on the side. In this track’s ladder it sits at the practitioner level beside QA Engineer and Test Engineer. Titles vary. The job does not.
An SDET does three things a manual tester does not and a product developer usually will not:
- Builds and maintains the test framework. The fixtures, the test-data factories, the CI configuration, the reporting, the conventions every other test follows. This is infrastructure, and it needs the same care as production infrastructure.
- Decides what is worth automating and at which level. Not every check belongs in a browser. Most belong lower down, and the SDET is the person who says so.
- Owns the health of the suite. Run time, flake rate, the quarantine list, the dashboard. When the suite is slow or untrusted, it is the SDET’s problem first.
What an SDET should not do is write every test. A suite written by one person for code written by twenty is always behind and always someone else’s. The modern pattern, which Google describes in Software Engineering at Google and most scale-ups have adopted, is that feature engineers write the tests for their features and the SDET builds the road they drive on. The disagreement among practitioners is about how far to take that. Some teams have no testers at all and treat that as the goal. Others find that without a person whose job is the suite, nobody fixes the framework and the flake rate climbs. The test strategy for your team, covered in test strategy and test plans, is where you settle it.
What to automate, and where
Automation pays when a check is run often, is stable enough to be worth encoding, has a clear oracle (a pass or fail a machine can judge), and guards something whose failure costs real money or trust. Exploratory testing, covered in exploratory testing and charters, finds the bugs you did not think to check for. Automation keeps the ones you have already found from coming back. They are complements, not rivals.
Four questions for any candidate check:
- How often will it run? A check you need on every merge is a strong candidate. A check you need once a year before an audit may be cheaper by hand.
- Is the feature stable? Automating a screen the designers will rebuild next month is buying maintenance.
- Can a machine tell pass from fail? “The balance is 104.50” is automatable. “The onboarding feels clear” is not.
- What does a miss cost? A broken card-freeze button on a card platform is a fraud exposure. A misaligned footer is not.
Then choose the level. The rule is to test at the lowest level that can catch the bug, because lower levels are faster, more deterministic and point closer to the cause.
| Level | What it catches | Speed | Flake risk | Typical owner |
|---|---|---|---|---|
| Unit | Logic errors, edge cases in one function or class | milliseconds | very low | the engineer who wrote the code |
| Component or integration | Wiring between your code and a database, queue or framework | tens of ms to seconds | low to medium | feature team |
| API or contract | Request and response shapes, status codes, idempotency | seconds | medium | feature team, SDET reviews |
| End-to-end browser or mobile | Whole user journeys across services | tens of seconds each | high | SDET and feature team |
This is Mike Cohn’s test pyramid, which Ham Vocke’s The Practical Test Pyramid on Martin Fowler’s site explains properly. Kent C. Dodds’s “testing trophy” argues for more weight on integration tests; Mike Wacker’s 2015 post on the Google Testing Blog argues hard against a top-heavy suite. Where practitioners agree is the shape at the top: end-to-end tests are the most expensive kind you will own, so keep them to the journeys that move money or would make the news if they broke. Login. Card activation. Payment. Freeze. A dozen to a few dozen, not hundreds.
Record-and-replay versus a coded framework
There are two ways to produce browser tests, and the choice shapes the next three years of your suite.
Record-and-replay tools watch you click through the app and save the steps. Selenium IDE does this, Playwright ships a recorder called codegen, and a crowd of commercial low-code products sell it as their main feature, often with “self-healing” selectors that try to find an element after the page changes. The appeal is real: people who do not write code can produce tests on day one.
Coded frameworks are libraries you write tests against in a programming language. The ones you will meet most are Playwright (Microsoft, TypeScript, Python, Java and .NET, drives Chromium, Firefox and WebKit from outside the browser), Cypress (JavaScript and TypeScript, runs inside the browser beside your app, with a strong interactive runner), and Selenium WebDriver (the W3C WebDriver standard, every major language, the oldest and most widely supported).
| Record-and-replay | Coded framework | |
|---|---|---|
| Time to first test | minutes | a day or two to set up |
| Who can write tests | anyone | people who can code |
| Lives in the app repo and code review | rarely | yes |
| Reuse (a login helper, a data factory) | weak; steps are copied | functions and fixtures |
| Waiting strategy | recorded timings or tool heuristics | explicit conditions you control |
| Cost at 300 tests | high: each UI change touches many recordings | lower, if the abstractions are good |
| Vendor lock-in | often | low for open-source frameworks |
The failure of recorded suites is not that they do not work. It is that they do not scale. A recording is a script with no abstractions: change the login page and you re-record forty tests. Recorded waits encode how fast the app was on the day you recorded. The tests live outside the code review where engineers would see them break. Most teams that start with a recorder end up rewriting in code, and the rewrite costs more than starting there would have. The honest case for a recorder is narrow: a small, stable app; nobody on the team who codes; a short-lived need. Using a recorder to draft a coded test, then cleaning it up, is a different and good practice.
Flake: what causes it and how to wait properly
Martin Fowler’s Eradicating Non-Determinism in Tests lists the causes, and fifteen years on the list holds: lack of isolation, asynchronous behaviour, remote services, time, and resource leaks. In browser tests the commonest by far is asynchronous behaviour handled with a sleep.
Here is a test for freezing a card at Halcyon Card, a fictional card-issuing platform, written the way a recording or a hurried engineer writes it:
import { test, expect } from '@playwright/test';
test('customer can freeze a card', async ({ page }) => {
await page.goto('/cards/4821');
await page.click('#btn-freeze');
await page.waitForTimeout(3000); // hope the API has answered
const status = await page.textContent('.card-status');
expect(status).toBe('Frozen'); // checked once, no retry
});
Three things are wrong. The sleep makes every run three seconds slower and still fails on the day the API takes 3.1 seconds. The selectors are tied to CSS ids and classes that a redesign will rename. And the assertion reads the text once, so it cannot tolerate the status arriving a moment late. Here is the same test with Playwright’s web-first assertions, which retry until the condition holds or a timeout expires (five seconds by default, per the Playwright docs):
import { test, expect } from '@playwright/test';
test('customer can freeze a card', async ({ page }) => {
await page.goto('/cards/4821');
await page.getByRole('button', { name: 'Freeze card' }).click();
await expect(page.getByRole('status')).toHaveText('Frozen');
});
It is faster on a good day, tolerant on a bad one, and it reads like the requirement. The locator finds the button the way a user does, by role and accessible name, which survives a restyle. Cypress has the same idea under the name retry-ability: queries and assertions retry until they pass or defaultCommandTimeout (four seconds) expires.
cy.contains('button', 'Freeze card').click();
cy.get('[data-testid="card-status"]').should('have.text', 'Frozen');
The other causes need other cures. Isolation: every test creates its own data through an API or factory and never shares an account with another test; the moment two tests use the same card, parallel runs collide. Time: tests that depend on the clock fail at midnight, at month end and on 29 February; control it. Playwright’s clock API pins the page’s time:
await page.clock.setFixedTime(new Date('2026-03-31T23:59:00Z'));
Remote services: a third-party sandbox that is down is not your bug; stub it in the gating suite and check the stub against the real thing with a contract test, which API, contract and integration testing covers. Concurrency: some flakes are real data races in the product, and a test that fails one time in two hundred may be the only witness. That is why you never delete a flaky test without finding out why it flakes.
Retries, quarantine and the flake budget
Every framework offers retries. Playwright’s runner, given retries: 2, reports a test that failed and then passed as “flaky” rather than “passed”, which is the right behaviour: the retry unblocks the merge, and the report still tells you. Retries become harmful when nobody reads that report. Google’s post describes the same trade from the inside: marking a test flaky so it fails only after three consecutive failures “reduces false positives, but encourages developers to ignore flakiness in their own tests”.
Quarantine is the other tool. Fowler’s advice is to “place any non-deterministic test in a quarantined area”: out of the gating suite, still running, visible on a list. Google describes a tool that quarantines tests automatically when flakiness crosses a threshold and files a bug. The weakness of both is the same. A quarantine with no owner and no deadline is where tests go to die, and the bugs they would have caught go with them.
A flake budget ties these together. It is a written agreement with three parts:
- The measure. Usually the share of gating-suite runs in a week that contain at least one test that failed and then passed on the same commit. Your CI or the framework’s report gives you this.
- The ceiling. A number the team agrees, with its source. Google’s 1.5% is a figure per individual test run, from a very large codebase, so it is not the same unit as a budget for whole suite runs: at 1.5% per test, a suite of a few hundred tests would flake on almost every run. For the suite, a starting rule of thumb many teams use is that no more than one run in fifty needs a retry to go green, and any single test that flakes twice in a week is quarantined.
- The consequence. What happens when the budget is spent: flake fixes jump the queue for the owning team, new end-to-end tests pause, or the SDET gets a day of the sprint. Without a consequence the budget is a chart.
Ownership: who fixes the red build
The question that decides whether a suite survives is who fixes a test when it fails. If the answer is “QA”, feature engineers will merge changes that break tests and wait for QA to update them, and the suite will always lag. If the answer is “whoever broke it”, tests must live in the same repository as the code, run in the same pull request, and be readable by the person who broke them.
A workable split: the team that owns a feature owns its tests, including the end-to-end tests for its journeys, and fixes or quarantines them within an agreed time. The SDET owns the framework, the shared fixtures, the CI wiring, the flake dashboard and the quarantine list, and reviews new end-to-end tests the way a staff engineer reviews a new service. Use a CODEOWNERS file so the right people are asked to review test changes. Write the split down in the automation plan, because when it is not written the default is that QA owns everything.
Day to day
Every morning, fifteen minutes. Read the overnight and main-branch runs. Sort failures into real bugs (file them), broken tests (route to the owning team), and flakes (log them against the test). The flake log is the raw data for your budget.
During the day. Most of your time goes on three kinds of work. Framework work: a new fixture, a faster setup that seeds data through the API rather than clicking through the UI, parallelisation, sharding the suite across CI machines. Review: pull requests that add or change tests, where you look for sleeps, shared data, brittle selectors and checks that belong at a lower level. Pairing: sitting with a feature engineer while they write the first end-to-end test for a new journey, because the second one they write alone.
Weekly, thirty minutes. A flake review with the engineering leads. You bring the numbers: run time trend, flake rate against budget, the quarantine list with each item’s owner and age. Anything quarantined for more than two weeks gets a decision: fix, rewrite at a lower level, or delete with a note saying what coverage was lost. The same flake rate, defined the same way, goes on the quality dashboard described in quality metrics.
In planning. You read the stories for the sprint and say which ones need new automated checks and at which level, before the work starts. This is where you stop the end-to-end test that should have been a unit test.
Quarterly. You revisit the automation plan. What did the suite catch? What escaped to production that a test should have caught, and at what level would it have been cheapest to catch? What can be deleted? Suites grow by default; pruning is a decision you have to make deliberately.
The cadence matters more than any single activity. A suite left alone for a month rots: selectors drift, quarantine fills, run time creeps past the point where engineers wait for it. Fifteen minutes a day keeps it trusted.
There is no SDET. Engineers write unit tests, maybe API tests, and someone has set up Playwright or Cypress with five tests for signup and payment. Your job, if you are the first quality hire or the engineer who cares, is to keep that handful green and fast, put it in the pull request pipeline, and refuse the temptation of a recorder that promises a hundred tests by Friday. Write a one-page plan with the five journeys, who fixes a red build, and one rule: no sleeps.
This is where the SDET role is created, usually because the suite has grown to a few hundred tests, takes forty minutes, and nobody trusts it. Your first quarter is triage: measure flake, quarantine the worst, cut run time with parallelism and API-seeded data, and move checks down the pyramid. Your second is ownership: get the tests into the product repositories, CODEOWNERS in place, and a flake budget agreed with the engineering managers. Framework choices made now will last years.
Automation is a platform with its own team: shared libraries, a device and browser grid, a flake-detection service, dashboards per product line. The technical problems are scale (tens of thousands of tests, hours of compute) and the political ones are ownership across dozens of teams and legacy suites in three frameworks that nobody will fund rewriting. You negotiate standards rather than impose them, and you measure flake and run time per team so the conversation is about numbers, not blame.
Template
# Automation plan: <product or team>
Author · Date · Review date · Status
## Scope
What this suite protects: <journeys, services>
Out of scope: <what is tested elsewhere or by hand, and why>
## What we automate, and where
| Journey or check | Level (unit / API / contract / E2E) | Why this level | Runs on (PR / main / nightly) |
|---|---|---|---|
## What we do not automate
- <check> — <reason: low frequency, unstable feature, no machine oracle, covered lower down>
## Framework and conventions
Framework: <name, version> · Alternatives considered: <and why not>
Locators: <role and accessible name first; test ids where needed>
Waiting: <web-first assertions; no fixed sleeps>
Test data: <created per test through API or factory; no shared accounts>
Time and third parties: <clock control; stubs plus contract tests>
## Ownership
| Suite or area | Owning team | Fix or quarantine within | Reviewer |
|---|---|---|---|
Framework, CI wiring, dashboards: <SDET or platform team>
## Flake budget
Measure: <e.g. share of gating runs needing a retry, weekly>
Ceiling: <number, and where it came from>
Retries: <count, and how retried passes are reported>
Quarantine rule: <trigger, owner, maximum age>
When exceeded: <consequence>
## Run time
Gating suite target: <minutes> · Current: <minutes> · How we keep it: <parallelism, sharding, level moves>
## Review
Weekly flake review: <who, when> · Quarterly plan review: <date> WORKED EXAMPLE
Halcyon Card is a fictional card-issuing platform: 140 people, 2.3 million active cards for 60 fintech clients, a web dashboard for clients and a cardholder app. The SDET wrote this for the cardholder team.
Scope. Protects card activation, freeze and unfreeze, PIN view, spend controls and the transaction list. Authorisation decisions are out of scope; the authorisations team has its own suite.
What we automate. Freeze rules and spend-limit logic: about 400 unit tests, every pull request. Card state API, including idempotent freeze: 85 API tests, every pull request. Contract tests between the app and the card-state service. End-to-end in Playwright: 14 journeys (activate, freeze, unfreeze, view PIN with step-up, set a spend limit, dispute a transaction), every pull request on Chromium, nightly on WebKit and Firefox.
Not automated. Visual polish of card art (no stable oracle; design review). The annual PIN-reset letter flow (runs once a year; manual script).
Framework. Playwright over Cypress for WebKit coverage of the iOS-heavy user base and multi-tab step-up flows.
Ownership. Cardholder team owns all 14 journeys; red test fixed or quarantined within one working day. SDET owns fixtures, CI and the dashboard.
Flake budget. Measure: share of gating runs needing a retry. Ceiling: 2% weekly, a team rule of thumb set after measuring 7% last quarter. Retries: 1, reported as flaky. Any test flaking twice in a week is quarantined with a ticket; maximum age ten working days. Over budget: no new end-to-end tests until back under.
Run time. Target 8 minutes for the gating suite, currently 13; four shards and API-seeded cards should close the gap.
Now you
You have joined Murmur, a fictional voice and video calling API, as its first SDET. Murmur has 90 people, a developer console where customers create projects, manage API keys and view call logs, and SDKs for web, iOS and Android. There are 210 Cypress tests for the console, all end-to-end, taking 38 minutes on every merge; engineers have started merging on red because the suite fails roughly one run in five and passes on rerun. A third of the tests share one test account. Nobody owns the suite since the engineer who wrote it left. The VP of engineering wants the merge pipeline under ten minutes this quarter, and the head of product wants automated checks for a new billing page launching in six weeks. Complication: the SDK teams want help too, and there is one of you. Write Murmur’s automation plan for the next two quarters.
Self-check
You are the only SDET at Dunnock, a fictional 90-person video calling API with no automated suite yet. The QA team is three manual testers who do not code and run a 400-case regression spreadsheet over two days before each monthly release. A vendor has demonstrated a codeless record-and-replay tool with self-healing selectors; the head of QA likes it because the testers could automate the spreadsheet themselves within a quarter. Engineering wants releases weekly. What do you recommend for the console's automation?
- POST Flaky Tests at Google and How We Mitigate Them John Micco, 2016
The source of the 1.5%, 16% and 84% figures, and an honest account of how retries and quarantine help and hurt. Read it to argue for a flake budget with numbers.
- POST Eradicating Non-Determinism in Tests Martin Fowler, 2011
The taxonomy of flake causes (isolation, async, remote services, time, leaks) with a cure for each, and the case for quarantine. Still the best single page on the subject.
- DOC Playwright: Assertions Playwright
How auto-retrying assertions work and which ones exist. Read it with the Best Practices page before writing your first test.
- DOC Playwright: Retries Playwright
How retries are configured and why a retried pass is reported as flaky rather than passed. Read it before you set retries in CI.
- DOC Cypress: Retry-ability Cypress
Which commands retry and which do not, and why chaining an action after a query matters. Essential if your suite is in Cypress.
- POST The Practical Test Pyramid Ham Vocke, 2018
A long, concrete walk through each level of the pyramid with code. Read it to decide where a check belongs before you automate it.
- POST Just Say No to More End-to-End Tests Mike Wacker, 2015
The Google Testing Blog's case against a suite built mostly of end-to-end tests: slow feedback, flake and failures that do not point at the bug. Read it before you add the next browser test.
- BOOK Software Engineering at Google, chapter 14: Larger Testing Winters, Manshreck and Wright (eds.), 2020
How Google structures tests bigger than unit tests, including fidelity, flakiness and who owns them. Read the sections on flakiness and on ownership. Read: Chapter 14, free online.
All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.