Fran Marcano
Device layer, back to the systems

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.

  1. The output is code in the team's repository. People review and merge it, and nothing a run depends on lives in the agent.
  2. A run never calls a model. It costs device minutes and, when it fails, leaves code, a screenshot and a video anyone can open.
  3. 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, logs

One path calls a model

Authoring and running a test, side by side

Fig. 1: the five parts and the two paths through them. The team asks the control service to automate or to run a scenario. Authoring, the only path that calls a model: the control service sends the authoring agent the job, files, phone and test account; the agent drives a phone in the device cloud and returns the outcome, files and reason, and asks the service for a fresh phone connection with a per-job token. The control service reads scenarios and step code from the team's repository and opens pull requests there, which the team reviews and merges. Running, with no model: the control service sends step code and run configuration to the device cloud, the runtime asks a test-data service for a one-time password, and the verdict, video and logs come back to the control service. automate run job, files, phone, test account drives outcome, files, reason fresh phone connection (per-job token) reads scenarios and step code opens pull request reviews, merges step code + run configuration runtime asks for a one-time password verdict, video, logs Team Control service owns the job jobstest accountsbuildsphonessessionspull requestscostverdicts Authoring agent writes step code SUBAGENT APPIUM OVER MCP Device cloud real phones Team's repository one per domain feature filesstep coderuntime Test-data service outside the five parts Fig. 1: the two paths, as two lanes. Authoring, the only path that calls a model: the team asks the control service to automate; the service sends the authoring agent the job, files, phone and test account; the agent drives a phone in the device cloud and returns the outcome, files and reason, and asks for a fresh phone connection with a per-job token. The control service reads scenarios and step code from the team's repository and opens a pull request, which the team reviews and merges. Running, with no model: the team asks the control service to run; the service sends step code and run configuration to the device cloud; the runtime asks the test-data service for a one-time password; the verdict, video and logs return to the control service. Authoring · calls a model automate job, files, phone, test account outcome, files, reason fresh phone connection (per-job token) drives reads scenarios and step code, opens pull request reviews, merges Team Control service owns the job jobs · test accounts · builds · phones sessions · pull requests · cost · verdicts Authoring agent SUBAGENT APPIUM OVER MCP Device cloud real phones Team's repository feature files · step code · runtime Team Run · no model run step code + run configuration verdict, video, logs runtime asks for a one-time password Team Control service Device cloud real phones Test-data service outside the five parts
Fig. 1Only authoring calls a model. Runs replay the step code in the team's repository, merged or in review, on the same real phones.

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 transactions

The agent writes the code behind those three lines.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. It runs the final files once more, this time without the model.
  6. 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.
  7. 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

Fig. 2: one authoring job, in seven steps, across the person, the service, the agent, the phone and the repository. 1. The person asks the service to automate a scenario. 2. The service lends a test account, opens a session on the phone and installs the build. 3. The agent plans, then runs the step code already in the repository on the phone; if it passes, the job ends as already passing. 4. Otherwise the agent explores, writes steps and runs them on the phone, until run 1 passes. 5. Run 2 passes with no model. 6. The agent returns the outcome, files and reason to the service, and the service commits to the rolling pull request and changes the tag. 7. The person reviews and merges in the repository. Person Service Agent Phone Repository 1 automate this scenario 2 lend test account, open session, install build 3 plan run the existing step code passes already passing 4 explore, write steps, run them run 1 5 run 2 NO MODEL 6 outcome, files, reason commit to rolling pull request, change tag 7 review, merge Fig. 2: one authoring job, in seven steps. 1. Person to service: automate this scenario. 2. Service to phone: lend test account, open session, install build. 3. Agent: plan; agent to phone: run the existing step code; if it passes, the job ends as already passing. 4. Agent and phone: explore, write steps, run them; run 1 passes. 5. Agent to phone: run 2 passes, with no model. 6. Agent to service: outcome, files, reason; service to repository: commit to rolling pull request, change tag. 7. Person to repository: review, merge. 1 Person → Service automate this scenario 2 Service → Phone lend test account, open session, install build 3 Agent plan Agent → Phone run the existing step code passes already passing 4 Agent ↔ Phone explore, write steps, run them run 1 5 Agent → Phone run 2 NO MODEL 6 Agent → Service outcome, files, reason Service → Repository commit to rolling pull request, change tag 7 Person → Repository review, merge
Fig. 2If the code in the repository already passes, the agent doesn't explore.

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

Fig. 3: the states of one authoring job and how it can end. A job starts by verifying the step code already in the repository, before exploring. If it passes, the job ends as already passing: nothing to publish. If no working code exists, the agent explores, then runs the code: run 1, then run 2 with no model, and the job ends as ready: code in the rolling pull request. If run 1 fails, the agent goes back to exploring. If run 1 changed the test account's state, it is not repeated, the pull request notes it, and the job ends as ready. If run 2 fails, or the exploration budget is spent, the job ends as draft: a draft pull request with the agent's reason. If the scenario is impossible on this OS, the job ends as impossible on this OS: a reason, and nothing published. An infrastructure error, a time or planning limit, or refused files, at any point, end the job with no outcome: a reason and who acts next. A draft is never promoted to ready, and a spent budget never leads to impossible on this OS. no working code passes passes fails changed account state not repeated, noted in the pull request passes scenario impossible budget spent fails never promoted budget spent infrastructure error, time or planning limit, or files refused, at any point verify before exploring explore run 1 run 2 NO MODEL ready code in the rolling pull request already passing nothing to publish impossible on this OS reason, nothing published draft draft pull request with the agent's reason no outcome reason and who acts next Fig. 3: the states of one authoring job, top to bottom, and the end states. Verify, before exploring: if it passes, already passing; with no working code, explore. Explore can end as impossible on this OS, or as draft when the budget is spent, never as impossible. Run 1: if it fails, back to explore; if it changed the account state, ready, not repeated and noted in the pull request; if it passes, run 2 with no model. Run 2: if it fails, draft; if it passes, ready. An infrastructure error, a time or planning limit, or refused files, at any point, end with no outcome. What the team sees: ready, code in the rolling pull request; already passing, nothing to publish; draft, a draft pull request with the agent's reason; impossible on this OS, a reason and nothing published; no outcome, a reason and who acts next. A draft is never promoted to ready. no working code passes passes verify before exploring explore run 1 run 2 NO MODEL ready passes already passing impossible on this OS budget spent draft budget spent impossible on this OS fails back to explore changed account state ready not repeated, noted in the pull request fails draft infrastructure error, time or planning limit, or files refused, at any point no outcome End state · what the team sees ready code in the rolling pull request already passing nothing to publish draft draft pull request with the agent's reason never promoted ready impossible on this OS reason, nothing published no outcome reason and who acts next
Fig. 3Ready takes two clean runs, or one that the pull request flags. A draft is never promoted, and an empty budget never means impossible.

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

Fig. 4: what lives in one team's test repository, and the pull requests the service opens. A schematic repository holds feature files, written by the team; step definitions, written by the agent or a person; a shared runtime, pinned, copied in and read-only; and a manifest, the same bytes for a version in every repository. The step definitions import the shared runtime. The team writes the feature files. The control service commits the agent's code to a pull request and pins the runtime's version and commit. The service opens four kinds of pull request: rolling, with ready code; draft, with the agent's reason; runtime upgrade, with runs already started; and first setup, with the runtime and manifest. The team reviews, merges or closes them. writes commits the agent's code to a pull request pins version and commit import reviews, merges, or closes Team Control service Team's repository feature files written by the team step definitions written by the agent or a person shared runtime pinned, copied in, read-only manifest same bytes for a version in every repository Pull requests the service opens Rollingready code Draftwith the agent's reason Runtime upgraderuns already started First setupruntime and manifest Fig. 4: what lives in one team's test repository, and the pull requests the service opens. Feature files, written by the team. Step definitions, written by the agent or a person, which the control service commits to a pull request and which import the shared runtime. The shared runtime, pinned, copied in and read-only, whose version and commit the control service pins. The manifest, the same bytes for a version in every repository. The pull requests the service opens: rolling, ready code; draft, with the agent's reason; runtime upgrade, runs already started; first setup, runtime and manifest. The team reviews, merges or closes them. writes commits the agent's code to a pull request pins version and commit import reviews, merges, or closes Team Control service Team's repository feature files written by the team step definitions written by the agent or a person shared runtime pinned, copied in, read-only manifest same bytes for a version in every repository Pull requests the service opens Rollingready code Draftwith the agent's reason Runtime upgraderuns already started First setupruntime and manifest
Fig. 4The team writes the feature files and merges everything else. Step code and each runtime version arrive by pull request.

Controls

Risks and their controls

None of these controls depends on the model following an instruction in its prompt.

Risks and their controls
RiskControl
Someone outside the team starts a jobThe service checks membership, and an allowlist decides which teams can start jobs and runs.
A job reaches another job's phoneA per-job token. The service keeps only its hash.
Test-account data lands in the repositoryThe agent rejects such step code, and the service checks the files again before publishing.
A layout shift breaks a selectorThe agent rejects new native selectors that match only by position.
A job runs away with cost or timeA 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 useA janitor reclaims them.
A rollout goes wrongOff by default, a kill switch that stops new jobs at once, and a log of each settings change.
Spend goes unseenThe 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

  1. 85 → 3–4 min

    per new test

  2. 5 min → 18.5 s

    login 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 agent

Contact

What should your team stop doing by hand?

LinkedIn