Agentic test automation · Architecture
The model writes the test once. Every run after that is plain code.
The mobile scenarios were written down but ran by hand before every release. Now an agent writes each test on a real phone in about 3–4 minutes, and every run after that replays code in the team's repository.
- Model in the loop
- Authoring only
- Runs
- In CI, on real phones
- Drivers
- Appium and Playwright, over MCP
Contents
The mobile suite was a set of scenarios in plain language, such as log in, send a transfer or make a deposit, with no automated test behind them. Automating one took about 85 minutes of an automation engineer's time.
I wanted more of those scenarios automated without asking an automation engineer for each one. Writing a test takes judgment calls a model is good at, like finding a path through a screen it has never seen. It is the wrong thing to put inside every run, where a team wants the same steps each time and failures it can read. So the agent writes the test once, the team reviews it like any other code, and from then on the test replays those steps with no model in the run.
The same design runs for web. There the agent drives a browser through Playwright instead of a phone through Appium, and the output is the same step code. The numbers here come from mobile, where it started.
Decisions
From an IDE agent to one behind a service
The first version lived in the IDE. It helped only the engineers who installed it and kept it configured, and I wanted teams to think only about what the app must do. So I moved the agent behind one service that owns each job.
Today the authoring agent is one of the subagents of the general agent that engineers reach from the team chat; the platform article covers what they share. Authoring jobs skip the chat: the control service calls the subagent directly, once per job. It holds the skills, context and memory for this work, reaches each domain's repository and test cases through the service, and starts each job from the steps already there.
An improvement reaches every team on its next job, and so does a regression. That is why nothing the agent writes is trusted on its own. It has to earn ready, a person merges it, and a kill switch can stop new jobs at once. The other costs of one central agent are that a service outage stops authoring for every team, and an agent deploy restarts jobs in flight.
Constraints
Three rules
I designed the system and built its agent around three rules.
- The output is code in the team's repository. People review and merge it, and nothing a run depends on lives in the agent.
- A run never calls a model. It costs device minutes and, when it fails, leaves code, a screenshot and a video anyone can open.
- Nothing shows as passed unless it passed. Each job and each run ends with an outcome or a reason.
Two things were off the table: unreviewed code on the base branch, and code marked ready after a single pass.
Architecture
The parts and the calls between them
I call the agent's output step code. It covers the step definitions and helpers behind a scenario.
- The team writes scenarios in Gherkin feature files, a plain-language format for BDD, kept in Git in the team's repository (each domain has its own).
- The control service owns the job: one attempt to automate one scenario on one OS. It belongs to a test management service that already syncs the mobile teams' scenarios and runs their release campaigns. It manages each test's lifecycle (test accounts, builds, phones, sessions and results), driving the device cloud through its APIs.
- The authoring agent writes and tests step code. The service calls it in turns, a short planning turn and then exploration, each a single streamed call. It drives the phone through Appium over MCP, so the phone becomes a set of tools the model can call. It reads a repository only through the files the service sends, has no tool that writes to one, and calls back only to ask for a fresh connection to the job's phone.
- The device cloud supplies real phones, from the same pool for authoring and for runs.
- The team's repository holds the feature files, the step code and a pinned copy of a shared runtime: login, one-time passwords from a test-data service, waits, OS dialogs, location and test data.
automate(scenario, os, build) -> job
turn(job, files, phone, account, budget) -> events, outcome, files, reason # the only path to a model
reconnect(job, token) -> phone # the agent's only call back
run(scenario, os, build, branch) -> verdict, screenshot, video, logsOne path calls a model
Authoring and running a test, side by side
Lifecycle
One job, from scenario to pull request
A generic scenario:
Scenario: Recent activity shows after login
Given I am logged in
When I open my activity
Then I see my latest transactionsThe agent writes the code behind those three lines.
- A person picks a manual scenario from the team's test cases. Android goes first; iOS starts once Android is ready and reuses its step code.
- The service lends the job a QA test account of the right type, never a customer's, opens a session on a real phone and installs the chosen test build.
- A short planning turn comes first. Before it explores, the agent runs the step code already in the repository, and stops if that code passes.
- Otherwise it drives the phone and writes step definitions on top of the shared runtime, running them until the scenario passes or the job hits its model budget, its validation runs or its time limit.
- It runs the final files once more, this time without the model.
- The service checks the returned files, commits them to the repository's rolling pull request (the one open pull request that collects ready scenarios) and tags the scenario as automated.
- A person on the team reviews and merges.
After the code exists, a run is an ordinary test, started from the test catalog or CI, before or after the merge. The service sends the step code to the device cloud, and the verdict returns with a video and logs. When one fails, the team reports a bug if the app is wrong, or asks the agent again if the step code is.
Verify first, then explore
One authoring job, start to finish
Verification
Ready, draft and the other endings
One passing run can hide step code that passes only some of the time, so ready takes two passing runs in one session. The second runs the final files with no model in the loop, as every later run does.
A job ends with one of four outcomes, or with a reason instead. Ready puts the code in the rolling pull request. Already passing means nothing in the repository needs to change. Draft opens a draft pull request with the agent's reason. Impossible on this OS is a real answer too. The agent explains why, and nothing is published. A job with no outcome, after an infrastructure error, a time or planning limit, or files the service refuses, shows a reason and who acts next.
The service never promotes a draft. When the exploration's model budget runs out, the job ends as ready or draft, never as impossible, because an empty budget proves nothing about the scenario. A passing run that changed the test account's state, a deposit for example, isn't repeated, and the pull request says so.
Two runs are a floor. They don't show that the Then steps check the right thing; the team's review judges that.
Outcomes of one job
Outcomes, and what the team sees
Ownership
What lands in the team's repository
The service works by convention over configuration. A team writes its feature files, and the service decides the rest: the tag, the manifest, the pull request and the runtime version. Publishing changes only a scenario's tag, and the service makes that change; the words stay the team's. Editing an automated scenario marks its step code stale, and the team chooses to re-author it or keep running it.
My first publishing design opened one pull request per scenario. Scenarios in a repository share steps, so those pull requests conflicted and repeated the same step. The rolling pull request, with one job at a time starting from it, fixed both, at the price of serial authoring within a repository. Closing it sends every scenario in it back to manual, so the team's review is the veto.
A team's first job opens a setup pull request with the runtime, which the team merges first. Login, one-time passwords and OS dialogs, everything the agent relied on while exploring, come from that runtime, so a run never needs the agent to fill a gap and the step code a team reviews stays short.
The runtime is pinned and copied into each repository rather than installed at run time, so runs need no code-host or registry credentials. A fix to login is written once and reaches every repository as a pull request, with runs already started. The price is a copy per repository, and runs keep the old version until the team merges the upgrade.
The team merges every line
What lives in a team's test repository
Controls
Risks and their controls
None of these controls depends on the model following an instruction in its prompt.
| Risk | Control |
|---|---|
| Someone outside the team starts a job | The service checks membership, and an allowlist decides which teams can start jobs and runs. |
| A job reaches another job's phone | A per-job token. The service keeps only its hash. |
| Test-account data lands in the repository | The agent rejects such step code, and the service checks the files again before publishing. |
| A layout shift breaks a selector | The agent rejects new native selectors that match only by position. |
| A job runs away with cost or time | A model budget in the agent, time limits in the service, and a cancel for the requester or an admin. |
| Phones, jobs or accounts stay in use | A janitor reclaims them. |
| A rollout goes wrong | Off by default, a kill switch that stops new jobs at once, and a log of each settings change. |
| Spend goes unseen | The service records each job's model calls and device minutes; runs spend device minutes only. |
Trade-off
Repair, postponed on purpose
Keeping the model out of runs has a cost. When the app changes, someone asks the agent again. I postponed automatic repair on purpose, because repair designed before real breakages pile up would rest on guesses. So I wrote down when it gets built: when enough automated scenarios are in release campaigns and teams keep re-authoring tests soon after they fail.
What I can't answer yet is how often an app changes enough to break its tests once most scenarios are automated. The trigger leaves that to usage data.
Results
Results
-
85→ 3–4 minper new test
-
5 min→ 18.5 slogin replay · no model
- A new mobile test: about 85 minutes of an automation engineer's time, now about 3–4 minutes from the request to a written test, before the team's review.
- The login replay: about 5 minutes by hand, now 18.5 seconds on a real phone.
The control service is part of a test management service whose core I built. That service grew from a four-team pilot to every mobile team and retired a paid test-management license.
The control service and the authoring agent run in production. A person on the team merges every line.
Scope
Where this applies
It fits any team that ships a mobile or web app and writes its scenarios down. In crypto or banking, the tests also leave evidence a release review can open: the step code and the run's video. It takes a device cloud with an API, test accounts the service can lend per job, and one-time passwords that test code can get without a person. It also takes one repository per domain, since authoring is serial within each.
It fits less well when screens change faster than tests can be re-authored, because asking again may cost more than it saves, or when most of a team's flows change account state, because those pass once instead of twice, the pull request says so, and the team's review carries more of the weight. A team that doesn't write scenarios has nothing to start from, because the agent works from the feature file and doesn't write one.
Next system
The prompt carries the judgment. The limits live in code.
The same errors kept reaching the team chat, and the first answer depended on who was watching. Now a triage agent answers in the thread with the relevant telemetry already read, and its infrastructure tools can't reach production.
Triage agentContact