Token cost of agent-driven UI testing: interactive browser execution versus executable Selenium IDE scripts
Abstract
We compared two ways a coding agent can test a web UI. Both used the same 13 manual test cases for a 3-step, 15-field sign-up form with cross-field validation:
- Interactive execution: the agent drives a browser one action at a time and reads a page snapshot after each action.
- Executable script: the agent checks each case by running it, saves the cases as a Selenium IDE
.sidefile, and replays that file with a runner.
Every valid run passed all 13 cases. The costs, in input-equivalent tokens (cache reads at 0.1×, cache writes at 1.25×, output at 5×), were:
| Interactive | Script | Script saving | |
|---|---|---|---|
| Authoring (first run) | 242k | 95k | 2.6× |
| Regression run, agent-supervised | 204k | 54k | 3.8× |
| Regression run, runner alone | — | 0 | — |
- Billed input: the interactive arm consumed 1.24M input tokens to author and about 1.07M per regression run. The script arm consumed 0.28M and 0.17M.
- Speed: script regression runs took 58 s, against 137 s for interactive runs. The runner alone took 16 s.
- Break-even: the script approach was cheaper from the very first run, with no break-even point to wait for. After 10 regression runs, the interactive arm would have consumed about 3.6× the script arm's tokens; after 50, about 3.8×.
- Fidelity: all three interactive agents also took shortcuts the script could not, carrying page state between cases instead of resetting it.
Applied to the run rate measured on one developer's machine (about 1,500 test-case executions a month, 57% of them re-runs), scripts would save 68–82% of testing tokens: 17–21M input-equivalent tokens per developer per month, or 172–207M for a team of 10. Under a conservative fixed-overhead model, the saving is 41–72%. We describe one invalidated run caused by the test runner killing other WebDriver sessions, and the threats to validity of a small-sample study.
1. Introduction
Coding agents increasingly test the web interfaces they build. The common approach is to give the agent a browser tool (in the style of Playwright MCP or computer-use tools): the agent performs one action per tool call (open, fill, select, click) and receives a snapshot of the page after each action, which it reads to decide whether the expected result holds. We call this interactive execution. Every action costs a model round trip, and every snapshot is input tokens. The cost recurs in full every time the tests are run again.
An alternative is for the agent to write the test cases down as an executable script, here a Selenium IDE .side file. A runner then executes the script without the model. The agent spends tokens to write and check the script once. After that, a regression run costs one tool call and a pass/fail summary.
This note measures both approaches on the same task: 13 manual test cases for a 3-step, 15-field sign-up form with cross-field validation. It reports tokens, tool calls and wall-clock time for the first run (authoring) and for later regression runs. Our question is practical: when is it worth having the agent write the script, and by how much?
2. Method
2.1 System under test
The page is a single static HTML page (8.6 KB, no framework), served on 127.0.0.1:4391 and titled "Sign up: Acme Cloud". It has three steps:
- Account: full name, email, confirm email, password, confirm password.
- Profile: date of birth, country, state, postal code, phone.
- Plan: plan, seats, start date, end date, terms checkbox.
That makes 15 fields. Next validates the current step. Back keeps the values already entered. Create account validates step 3 and shows a summary. Each field's error appears in #err-<id>.
The cross-field rules are:
- The confirmation fields must match their originals.
- The password must not contain the local part of the email.
- The applicant must be at least 18, based on the date of birth.
- State is required when the country is the United States, and not allowed for any other country.
- The postal code format depends on the country (US: 5 digits; Canada: A1A 1A1).
- The phone number needs a country code, and US or Canadian numbers must start with +1.
- The seat range depends on the plan: Basic allows exactly 1, Pro up to 5, Team at least 3.
- The end date must be after the start date, and a Basic plan may last at most 365 days.
2.2 Test cases
There are 13 manual test cases (TC-1 to TC-13), written in plain language with numbered steps and expected results (tests/commonshell/signup-form.md). Both arms received the same cases:
- 11 cases check a validation rule, most of them cross-field.
- 1 case (TC-9) checks navigation and that values are kept.
- 1 case (TC-13) completes the whole form.
Each case starts from a fresh page and fills in any earlier steps it needs.
2.3 Arms
A. Interactive execution. The agent drives headless Chrome through a command-line browser tool (tools/bt.py, raw WebDriver over chromedriver 158, with a temporary profile). It has start, open, snapshot, fill, select, click and stop. Every action prints a compact page snapshot afterwards: headings, the current step, fields with their values and invalid state, visible errors and buttons. This is the observation a Playwright-style tool returns. The agent was told to use one tool call per browser action and not to chain actions in scripts.
B. Executable script. The agent follows a write-then-check workflow:
- Write each manual case as one test in a scratch
.sidefile. - Run it with Commonshell's runner (
cs test --side … --no-visual --no-reflect) and fix the test until it matches the page. - Append the checked test to
tests/commonshell/signup-form.side. - Finally, run the whole file.
The runner executes in its own headless Chrome and prints one line per command with ok or FAILED.
Regression runs. After authoring, each arm was run again on the unchanged page by a fresh agent with no memory of the first run:
- Arm A re-executes all 13 cases interactively, because it has no other artifact to reuse.
- Arm B runs the saved
.sidefile once and reports the result.
2.4 Agents and measurement
Every run is a fresh general-purpose sub-agent of the same model (the session's default sub-agent model) with a short task prompt (paper/prompts.md), and none sees another's context. We record the harness's own per-agent report:
- total tokens (input + output across all turns),
- the number of tool calls,
- wall-clock duration.
No arm was told what the other arm does. Both were told not to edit the page or the test cases.
We also timed the runner on its own, with no agent: one cs test invocation of the saved file, which uses no model tokens.
Input-equivalent tokens. Prompt caching makes raw token counts misleading. A cache read is billed at a tenth of an uncached input token, so we also report a weighted figure using Anthropic's published price ratios: uncached input ×1, cache write ×1.25, cache read ×0.1, output ×5. The harness's own per-agent "tokens" figure tracks each agent's peak context, not its total consumption, so we computed totals from the per-turn usage records in each agent's transcript.
3. Results
3.1 Correctness
Every valid run, authoring and regression, in both arms, reported 13 of 13 cases passing, and none found a defect in the form. The script arm also checked that its assertions can fail: it ran a copy of TC-10 with a wrong expected message, and that copy failed as it should. Two of the three interactive agents (A1, A2) also reported a minor usability issue that no test case covers: an error stays on screen after the field is fixed, until the next Next or Create account click. No script-arm agent reported it.
3.2 Cost per run
Table 1 reports every run. Billed input is uncached input plus cache writes plus cache reads.
| Run | Arm | Phase | Tool calls | Model turns | Wall time (s) | Billed input | Output | Input-equivalent | Peak context |
|---|---|---|---|---|---|---|---|---|---|
| A1 | Interactive | Authoring | 82 | 28 | 158 | 1,236,798 | 11,628 | 241.9k | 59.7k |
| A2 | Interactive | Regression 1 | 69 | 30 | 143 | 1,099,950 | 9,822 | 198.1k | 47.3k |
| A3 | Interactive | Regression 2 | 73 | 25 | 131 | 1,033,544 | 10,081 | 210.3k | 56.7k |
| B1 | Script | Authoring | 7 | 8 | 147 | 277,815 | 5,865 | 94.8k | 40.3k |
| B2 | Script | Regression 1 | 5 | 6 | 60 | 176,273 | 1,754 | 58.2k | 35.1k |
| B3 | Script | Regression 2 | 4 | 5 | 56 | 156,523 | 1,475 | 49.3k | 36.3k |
| R | Runner only | Regression | 1 | 0 | 16 | 0 | 0 | 0 | 0 |
| A0 | Interactive | Authoring, invalid | 41 | 29 | 550 | 1,151,253 | 8,090 | — | 53.4k |
Table 1. Per-run usage. A0 was invalidated (§3.5) and is excluded from all averages.
Table 2 summarises the two arms.
| Interactive | Script | Ratio | |
|---|---|---|---|
| Authoring, billed input | 1.24M | 0.28M | 4.5× |
| Authoring, input-equivalent | 242k | 95k | 2.6× |
| Regression mean, billed input | 1.07M | 0.17M | 6.4× |
| Regression mean, input-equivalent | 204k | 54k | 3.8× |
| Regression mean, output tokens | 9.95k | 1.61k | 6.2× |
| Regression mean, tool calls | 71 | 4.5 | 16× |
| Regression mean, wall time | 137 s | 58 s (16 s for the runner alone) | 2.4× (8.6×) |
Table 2. Arm means.
The fixed cost of starting an agent explains most of the script arm's regression cost. Its peak context of about 35k tokens is mostly the system prompt and tool definitions: the cache writes in B2 and B3 were 23–28k tokens, for only 4–5 tool calls. The test content itself is small. The runner's pass/fail lines are under 1 KB, and its full log is about 19 KB.
3.3 Cumulative cost
The interactive arm has no artifact to reuse, so its cost recurs on every run. Table 3 extends the means to N regression runs after authoring, in input-equivalent tokens.
| Regression runs N | Interactive | Script, agent-supervised | Script, runner alone | Interactive ÷ supervised script |
|---|---|---|---|---|
| 0 (authoring only) | 242k | 95k | 95k | 2.6× |
| 1 | 446k | 149k | 95k | 3.0× |
| 10 | 2.28M | 633k | 95k | 3.6× |
| 50 | 10.45M | 2.78M | 95k | 3.8× |
Table 3. Projected cumulative input-equivalent tokens: authoring + N × regression mean.
The script arm is cheaper at every N, including N = 0. As N grows, the ratio between the two agent-driven arms tends to the per-run ratio of 3.8×. The runner-alone column shows the limit. When the runner is wired into CI or a hook that only calls the agent on a failure, regression runs cost no model tokens at all.
3.4 Process observations
- Interactive agents shortened their own procedure. Each of the three valid interactive runs reset the page less often than the prompt asked. They carried state from one case to the next (for example, "TC-5 to TC-13 in one session") and only changed the fields each case named. This lowers their cost, so the interactive figures are, if anything, an underestimate of the cost of the procedure as written. It also weakens the tests, because a later case can pass on data left over from an earlier one. The script arm cannot take this shortcut: every test starts with
openand fills the earlier steps itself. - The script arm batched its authoring. Instead of one scratch run per manual step, B1 wrote a small generator for the 13 per-case scratch files and ran them case by case. It used 7 tool calls in total, which is fewer round trips than a strict step-by-step workflow would make. A stricter protocol would raise B1's cost but would not change regression costs.
- Both arms changed the input method for some fields. All interactive agents hit a bug in our browser tool: the date fill fell back to key presses, so
1990-05-14became0514-12-09. Each agent worked around it by typing MMDDYYYY, which cost a few extra calls. The script arm set the dates and seat count withexecuteScriptinstead of typing. Both regression agents in that arm pointed out that this does not test typing or picking those values. Our form validates on Next and Create account, so the results hold here, but it would matter for a form that validates as the user types.
3.5 Invalidated run
The first interactive authoring run (A0) ran at the same time as the script authoring run (B1). The interactive agent's chromedriver kept dying about 5 seconds after each start, and A0 completed only TC-1 to TC-3. Afterwards we reproduced the cause: a single cs test run terminated a chromedriver that was running independently on another port. Commonshell's runner cleans up chromedriver processes it did not start. All later runs ran one at a time. A0 is reported in Table 1 for completeness only. It spent 1.15M billed input tokens without producing a usable result, a cost of fragile interactive tooling that a single-command runner does not risk in the same way.
4. Discussion
The difference comes from where the page observations go. In interactive execution, every action returns a page snapshot that becomes part of the agent's context and is re-read on every later turn. Prompt caching softens this but does not remove it: cache reads were over 95% of the interactive arm's billed input. In the script arm, the runner consumes the observations and returns only a verdict. The agent's context grows with the number of tests, not the number of actions: 240 recorded commands produced about 1 KB of summary.
Authoring costs the script arm something extra, because it has to write and debug JSON. Even so, it cost less than interactive execution of the same cases. The interactive arm needed 82 tool calls to perform 13 cases, while the script arm needed 7 to author and run all of them.
The interactive arm is not without merit. Its agents looked at the page after every action, so they noticed things outside the expected results. Two of the three interactive runs reported the stale-error usability issue (§3.1), and no script-arm agent did. That is a real advantage: a script only checks what it was told to check. For exploratory testing, interactive execution remains the natural tool. For tests that will be run more than once, the measurements favour writing them down.
5. Projected monthly savings for a team
5.1 How often the tool is run
We have no team-wide counts. Commonshell's usage counting started on 2026-11-22, it sends no per-user IDs, and it does not record individual test runs. We therefore measured the run rate of one developer's machine from its own run history (cs runs, 2026-11-17 to 2026-11-24), excluding this study's runs:
| Measure | Value |
|---|---|
| Test-case executions | 428 |
| Active days | 6 (of 8 calendar days) |
| Executions per active day | 71.3 |
| Runner invocations | 118 (3.6 test cases each) |
| Distinct tests | 182 (2.35 runs each) |
| First runs / re-runs | 43% / 57% |
| Failure rate | 15.4% |
Table 4. Observed test activity on one developer's machine.
This developer was building a testing product and worked with agents all day, so the rate is high. We report two scenarios:
- Observed: the measured rate over 21 working days, which gives about 1,500 test-case executions per developer per month (637 first runs and 861 re-runs).
- Typical: a quarter of that, about 370 per developer per month. This is an assumption, not a measurement.
5.2 Per-case cost
We divided each run in Table 1 by its 13 cases. In input-equivalent tokens, one test case cost:
| Interactive | Script, agent-supervised | Script, runner only | |
|---|---|---|---|
| First run (authoring) | 18.6k | 7.3k | 7.3k |
| Re-run | 15.7k | 4.1k | 0 |
| Raw tokens, first run / re-run | 96.0k / 82.8k | 21.8k / 12.9k | 21.8k / 0 |
| Time, first run / re-run | 12.1 s / 10.5 s | 11.3 s / 4.5 s | 11.3 s / 1.2 s |
Table 5. Per-case cost derived from Table 1.
5.3 Monthly totals
Monthly cost = first runs × first-run cost + re-runs × re-run cost (paper/monthly.py):
| Team size | Interactive | Script, agent-supervised | Saving | Script + runner | Saving | Agent hours: interactive / supervised / runner |
|---|---|---|---|---|---|---|
| 1 | 25.4M | 8.2M | 17.2M (68%) | 4.6M | 20.7M (82%) | 4.7 / 3.1 / 2.3 |
| 5 | 127M | 41M | 86M (68%) | 23M | 104M (82%) | 23 / 15 / 11 |
| 10 | 254M | 82M | 172M (68%) | 46M | 207M (82%) | 47 / 31 / 23 |
| 25 | 634M | 205M | 429M (68%) | 116M | 518M (82%) | 117 / 77 / 57 |
Table 6. Observed scenario, input-equivalent tokens per month. In raw tokens, a team of 10 would use 1.33B (interactive), 0.25B (supervised script) or 0.14B (script + runner) per month.
In the typical scenario, every figure in Table 6 scales by 0.25. A team of 10 would save about 43M input-equivalent tokens a month with supervised scripts, or 52M with the runner doing re-runs, and about 4–6 agent-hours.
5.4 Conservative bound
Table 6 scales costs from 13-case runs. Real invocations are smaller (3.6 cases on average), and if each one starts a fresh agent, that agent's fixed start-up cost is spread over fewer cases. We measured this fixed cost as 53.8k input-equivalent tokens, which is essentially the whole of a script regression run. Per-case marginal costs are then:
| Interactive, first run | Interactive, re-run | Script, first run | Script, re-run |
|---|---|---|---|
| 14.5k | 11.6k | 3.2k | ≈0 |
This gives 413 invocations per developer per month in the observed scenario, and these per-developer costs:
| Interactive | Script, agent-supervised | Script + runner | |
|---|---|---|---|
| Per developer per month | 41.4M | 24.2M | 11.5M |
| Saving vs interactive | — | 41% | 72% |
| Team of 10, saving | — | 172M | 299M |
In the runner column, an agent is involved only in invocations that author tests. So even under this bound, scripts save between two-fifths and nearly three-quarters of the tokens. The saving grows with the number of cases per run.
5.5 Reading the numbers
- Tokens are the main saving, not time. One developer at the observed rate saves about 1.6–2.4 agent-hours a month. A team of 10 saves about 16–24 agent-hours, most of which the developer would otherwise spend waiting. The token saving is 68–82% in the per-case model and 41–72% in the conservative model.
- Most of the saving comes from re-runs. Re-runs are 57% of executions, and a re-run costs almost nothing once the runner handles it.
- To convert to money, multiply input-equivalent tokens by the model's price for uncached input tokens.
6. Threats to validity
- Sample size. There was one authoring run and two regression runs per arm. The per-run variation was modest (A2/A3 within ±3% of their mean in input-equivalent tokens, B2/B3 within ±9%), but we give no confidence intervals.
- Our own browser tool. Arm A used a purpose-built tool whose snapshot is compact: a field list rather than a full accessibility tree. Accessibility-tree snapshots from tools such as Playwright MCP are typically larger, which would widen the gap. Its date-fill bug added a few calls to arm A.
- One page, one model. The form is a single small static page, and every run used the same model. Larger pages make snapshots bigger, which raises interactive costs. A different model may take a different number of turns.
- Prompt differences. Arm B's prompts included runner-specific advice, such as setting dates by script and how
executeScriptreports values. Arm A's tool handled dates itself, at least as documented. We tried to give each arm what it needed, not the same words. - Pricing weights. The input-equivalent figure assumes Anthropic's standard price ratios. Raw billed tokens are given alongside, so readers can apply other weights.
- Monthly projection. The run rate comes from one developer's machine over 8 days, during heavy agent-driven development, so the typical scenario's 25% factor is an assumption. Per-case costs come from one form whose cases averaged 18 commands. Run history may also be trimmed, which would make the observed rate an underestimate.
- Metric source. Totals come from the per-turn
usagerecords in each agent's transcript. The harness's own per-agent token figure is close to peak context, and we do not use it as a total.
7. Conclusion
Every valid run in both arms passed all 13 test cases. For a 13-case, 3-step form test, having the agent write a .side file and replay it cost:
- 2.6× fewer input-equivalent tokens to author,
- 3.8× fewer per agent-supervised regression run,
- none when the runner runs on its own.
It was also faster per regression run and kept each test independent. At the run rate measured on one developer's machine, this means 68–82% fewer testing tokens each month (41–72% in the conservative model). For a team of 10, that is 172–207M input-equivalent tokens and 16–24 agent-hours a month. The script approach paid for itself on the first run. Our recommendation for agent workflows is:
- Use interactive execution to explore.
- Turn checked manual cases into an executable script as soon as they are settled.
- Let the runner, not the model, carry the repeated runs.
Appendix A. Artifacts
form.html: the form (8.6 KB).signup-form.md: the 13 manual test cases.signup-form.side: arm B's script (13 tests, 240 commands, 27.9 KB).bt.py: arm A's browser tool.prompts.md: the agent prompts.usage.tsv: per-run token data.monthly.py: the monthly projection (§5).
Environment: macOS 26.7.3, Google Chrome 158.0.8127.88, chromedriver 158, Commonshell cs 0.1.0.
Appendix B. Incidental findings
- Commonshell's
cs testterminates chromedriver processes it did not start (§3.5). It should track and stop only its own drivers. - The runner does not support
assertVisibleorassertNotVisible.waitForElementVisibleandwaitForElementNotVisiblework instead. - Sometimes the runner prints a stray
kill: NNN: No such processline before its result. - In
tools/bt.py,filldoes not recognise date inputs, so it falls back to key presses, which Chrome reads in month/day/year order. The root cause is not confirmed.