·10 min read

Claude Code mobile app testing: a screen map

Claude Code re-read my game's code before every device test. A generated screen map took a fresh agent from one sentence to a passing test in three minutes.

claude-codeaitestingcapacitor

Contents

Functional testing on a device was the slowest part of finishing a game. I did it by hand, and when I asked Claude Code to do it instead, it was slow in a different way. Every test started with a tour of the codebase: find the screen, find the button, work out which piece of state means "the gift is claimed", then drive the phone one tap at a time. The next test paid for the same tour again.

I never timed the old way, so there is no before number here. What I have is the after: a fresh agent with no context went from one sentence to a passing test on an Android emulator in a little over three minutes, without opening a source file. This post is how the game got to that point, and what an outside review found wrong with it once it did.

The game is ASMR Logo Craft Block, a Capacitor app: a web UI inside a WebView, packaged for Android and iOS.

Where the time went

For Claude Code mobile app testing, the phone was never the slow part. Looking things up was. To check "claiming the daily gift pays the coins", an agent needs the screen's name, the element that claims, a way to put the game in a state where a gift is waiting, and where the coin count lives. None of that sits in one place in a codebase. The agent greps, reads five files, works it out, and forgets all of it when the session ends.

So the plan was to answer those questions once, in a file the agent reads instead of the code, and to save every test as a short scenario that reruns with one command and no AI at all. The agent's cost is paid once per scenario. After that it is an ordinary regression test.

Three pieces

The first piece is a test hook, compiled into QA builds only. The runner can ask it four kinds of thing:

  • which screen is up, and a snapshot of game state: coins, levels finished, settings, consent
  • start from a named seed, such as "past the tutorial, levels 1–23 finished, 1,250 coins"
  • do a game action: open level N, or solve the board with real touches
  • what the game asked analytics and ads to do

That last one was cheap. The game talks to analytics and ads through plain objects with methods, so one JavaScript Proxy wraps all of them and records every call. The hook lands in its own chunk of the QA build, and I grepped the release bundle for the recorder's code to confirm none of it shipped.

The second is the map. A command builds the game in QA mode, opens it in headless Chrome, asks the hook to describe itself and every seed's state, and scans the views for test ids. It writes one Markdown file in about 15 seconds. A simplified example of what it holds:

## Seeds
- `returning`: past the tutorial, no level finished, 100 coins
- `midGame`: levels 1-23 finished; the next level is 24
- `giftWaiting`: like returning, but today's daily gift is waiting (day 3)

## Test ids, by screen
**home**: `home.level.{id}`, `home.gift`, `home.shop`, `home.settings`
**rewards**: `rewards.claim`

The real file also lists every route, every action and every analytics event, plus a table of each state path's value under each seed. That table is what lets an agent write a coin check without reading the wallet code.

The third is a runner and a skill. Scenarios are YAML. The runner plays them through Appium, UiAutomator2 on Android and XCUITest on iOS, and every check polls until it holds or times out, so no scenario carries a sleep. It closes interstitials by itself. A failed run reports the step, a screenshot, the game state, the game's last calls and the app's device log. The Claude Code skill is short: read the map and the step reference, write a scenario, run it, read the report, and leave the game's source alone.

Every button needs a name

A map with gaps sends the agent back into the code, which is the thing being avoided. A button without a data-testid is a gap.

Grepping the views for click handlers, buttons, inputs and ARIA roles found 89 call sites. Most went through one shared button component that passes extra props down, so tagging each was one attribute. Then a unit test renders the real app, opens every screen and fails if any interactive element on the top layer has no id.

All twelve screens passed the first time, which proved nothing yet. I added a check that each screen has any controls at all, and removed the id from the claim button. Rewards went red, as it should. Home went red too: it plays a 3.7-second intro before its buttons render, so its first green had been a check of an empty screen. The test now waits for controls to appear. A later rule says the part of an id before the first dot must be the screen it sits on; I renamed home.stats to stats.open to see that one fail too.

CI regenerates the map and fails if it differs from the committed copy, so the file the agent trusts cannot drift from the game. That is the lesson from when the AGENTS.md rules piled up in a smaller form: a rule that can be a check should be one.

One sentence, no source

To find out whether the map was enough, a fresh subagent got the skill and one sentence: when today's daily gift is waiting, the game offers it by itself on home; claiming it pays the coins, and the gift card on home then says it is claimed. It was told not to edit the source and to list every file it read.

It took 187 seconds, 22 tool calls and about 73,000 tokens. It read the skill, the map, the scenario schema, two existing scenarios, one report and three screenshots. Nothing under src/. The scenario it saved, simplified:

name: The daily gift is offered and claimed
launch: { seed: giftWaiting }
steps:
  - expectScreen: rewards
  - expectState: { wallet.coins: 100 }
  - tap: rewards.claim
  - expectEvent: { name: earn_virtual_currency, params: { value: 20 } }
  - expectState: { wallet.coins: 120 }
  - tap: modal.close
  - expectScreen: home
  - expectVisible: { text: "Claimed!" }

It needed three runs, and the failed first one was the most useful output of the whole test. The map called the gift seed "day 3" of the login streak. On the emulator the popup offered day 1 and paid 10 coins. The skill kept the agent out of the source, so it matched its scenario to what the screen showed and reported the mismatch with a guess: the seed sets the streak's day counter but not the date of the last claim, so the game sees a broken streak and starts it over.

The guess was right. With the last claim set to yesterday in the seed, day 3 paid 20 coins and the scenario passed with those values. The bug was in my test hook, in a state no player can reach. It would still have meant a scenario that checked the wrong streak day for as long as it existed.

The report flagged two more gaps. The step reference was missing from the installed package, so the agent wrote the scenario from the JSON schema and the existing examples, and the schema turned out to be enough; the reference ships with the runner now. And nothing in the map marked the gift as claimed, so the agent checked for the text "Claimed!", which holds only while the game is in English. A test id on that label would be sturdier.

Running it without the agent

Once a scenario exists, the AI is out of the loop. Eight of them pass on an Android emulator and an iOS simulator: first launch with consent and the tutorial, winning a level, progress and settings surviving a restart, pause and resume, using a hint, the rating prompt asked only once, and the daily gift. The full Android suite takes about six minutes. Each interstitial costs about 9 seconds, nearly all of it AdMob's own countdown before the close button appears.

After about two hours of runs the emulator got two to three times slower, which turned out to be swap inside the emulator. I wrote that up separately in how to make Android emulator faster; the runner now warns before it starts on a swapping emulator.

What an outside review found

When it worked, two subagents that had not built it reviewed it: one the package, one how the game uses it. Each got the locations and the questions, not my conclusions. Their joint verdict was "not quite ready to roll out to many games", and the findings held up against the code:

  • Live ads. Once a game turns AdMob test mode off, a QA build on a real phone serves real ads, and the runner closes them automatically. AdMob can treat that as invalid traffic. QA builds now always request Google's test ads. Analytics stays on, and every QA build sets a user property build: qa so dashboards can filter the runs out.
  • A QA build could reach the store. The QA build wrote into the same native folders that a signed bundle and an Xcode archive are packaged from. A Gradle task and an Xcode build phase now refuse a release build that carries the hook. I checked both: Release refuses, Debug goes through.
  • The ad closer could press the game's buttons. An ad counted as "up" from the moment it was requested, so while it was still loading, a search for "Close" or "Skip" could match the game's own popup or the tutorial's skip. It now closes only while the ad's own screen is in front.
  • Weight. The in-game half pulled about 124 MB of Appium, WebdriverIO and Playwright into every game's install. It is split now: a dependency-free part the game imports, and a runner that lives on the development machine.
  • A crash left the last green report in place. If a run died before writing its report, "latest" still pointed at the previous one, possibly a pass. An agent told to read the latest report would read a pass that never happened. Every run now writes a report, interrupted or not, and a run that could not finish says so at the top and exits with code 2.
  • Wrong names passed the checker. A scenario naming a seed or test id the game does not have failed only minutes into a device run. The checker validates against the map now.

The last two weigh more because an agent reads the output. It takes the report at its word, and a typo it only learns about from a device run is a slow way round its own loop.

The iOS build that would not start

The first iOS run stopped at "Unable to start WebDriverAgent session". Building WebDriverAgent by hand showed the real error:

error: lstat(/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/lib/lib_TestingInterop.dylib): No such file or directory (2) (in target 'WebDriverAgentRunner' from project 'WebDriverAgent')
** TEST BUILD FAILED **

With Xcode 26.1, that library was nowhere on the machine. appium-xcuitest-driver 12.13.3 pins appium-webdriveragent to exactly 16.12.11, the first version that embeds it, and the newest release at the time, 16.13.6, still does. Driver 12.13.2 pins 16.12.10, which builds. With the driver pinned to 12.13.2, all eight scenarios passed on the simulator.

What I would keep

If you are setting up AI agent device testing for your own app, the agent's cost is in the lookups, and they can be paid for once:

  • Generate the map from the running build, and fail CI when the committed copy is stale.
  • Give every control a stable id, and make a missing one fail a test. Break it once to prove the test can fail.
  • Keep the agent out of the source and have it report what the map got wrong. That is how the seed bug surfaced.
  • Never let a report the agent reads be older than the run it just started.

It is the same idea as writing the repo instead of the prompt, pointed at a phone. The agent was never slow at tapping. It was slow at finding out what to tap.

More posts

New writing when there is something worth saying. By email or by RSS, whichever you prefer.