skip to content
all examples

Testing a Flutter app on Codemagic with e2e

A Flutter coffee-ordering app tested on an iOS simulator and an Android emulator in Codemagic, with the suite gating each release and the agent test replayed from a committed recording.

A small Flutter coffee-ordering app, tested end to end with e2e and built on Codemagic. e2e is an npm package, so the tests run on the build machine itself: a simulator on a Mac for iOS, an emulator on a Linux instance for Android. There is no server to host.

Try it

  1. Fork this repo and add it as an app in Codemagic.
  2. Create two empty variable groups on the app: e2e and android_release. The workflows list them, and they stay empty until you add a key.
  3. Start e2e-ios and e2e-android.

No accounts or secrets are needed. Seven tests run: six that find controls by test ID, and one where an agent orders a coffee. The agent step replays a recording committed in e2e/.e2e/cache/, so it needs no model and no key.

The agent test and the replay cache

An agent.act step asks a model to work through the app. The first run records what the agent did, and later runs replay those actions without a model call. The recording is plain JSON in e2e/.e2e/cache/. Read it before you trust it, as you would any test data. CI never writes to it.

The recordings were made once, locally, with Claude Code: one on an iPhone simulator and one on an Android emulator. Each belongs to this test, this instruction, one target and this bundle ID. That leads to three ways to use it:

  • Replay it. Do nothing. This is the default. Each workflow runs the agent test when it has a recording for its platform or a key.

  • Run it live. Add AI_GATEWAY_API_KEY (secure) to the e2e group and run npx e2e run --no-cache to see the model drive the app. The model is set in e2e/e2e.config.ts, and any AI SDK provider works.

  • Record your own. Change the instruction, the app or the bundle ID, and the recording no longer matches. Either start the record-cache workflow with a key set, which uploads a new e2e/.e2e/cache as an artifact to commit, or record locally:

    terminal
    cd e2e
    E2E_AGENT=claude-code E2E_RECORD_CACHE=1 E2E_IOS_DEVICE=<simulator UDID> npx e2e run --target ios tests/agent.e2e.ts
    # Android: E2E_ANDROID_DEVICE=<emulator serial> ... --target android

    E2E_AGENT=claude-code uses your Claude Code login (claude auth login) instead of a key. If you would rather drop the recording, run npx e2e cache clear. The test then skips until a key is set.

Skills for coding agents

The skills/ folder has two skills for Claude Code and other agents that read SKILL.md files:

  • skills/e2e-codemagic: adds e2e to a mobile app and sets up the Codemagic workflows, using this repo as the reference.
  • skills/codemagic-build-loop: starts a Codemagic build through the REST API, waits for it, finds the failing step, reads its log and fixes the cause.

To use them in your own project, copy the folders into its .claude/skills/ folder. The build loop needs a Codemagic API token in CM_API_TOKEN and the app's id in CM_APP_ID.

Workflows

WorkflowRuns onWhat it does
e2e-ios, e2e-androidpush, pull requestBuild the app, run the e2e suite, publish the JUnit report to the Tests tab
release-ios, release-androidtag v*Run the same e2e suite as a gate, then build the release
record-cacheby handRecord the agent test against a model and upload the recording

Releasing

The release workflows build from a revision only after it passes the e2e suite. Out of the box they stop short of the stores:

  • Android builds an app bundle, signed with the debug key.
  • iOS builds an unsigned archive.
  • The last step of each prints a message where the upload would happen.

To ship for real, the signing and publishing settings are already in codemagic.yaml as commented blocks. Each line starts with #| . Remove that prefix to enable a block. Codemagic code signing identities do the signing: you upload a certificate, profile or keystore once under Team settings, and the workflow refers to it by name. No keychain or keystore scripts are needed.

iOS

  1. Pick your own bundle ID and replace io.codemagic.samples.beanline in the Xcode project, android/app/build.gradle.kts, e2e/e2e.config.ts and the bundle_identifier line in codemagic.yaml. The agent test's recording belongs to the old ID, so re-record it or clear it, as described above.
  2. Register the bundle ID and create the app in App Store Connect.
  3. Under Team settings, add your App Store Connect API key (Developer Portal), and upload a distribution certificate and an App Store provisioning profile for the bundle ID (Code signing identities).
  4. In release-ios, put your key's name in the integrations block. Enable the ios_signing, integrations and publishing blocks and the two signed-build steps, and comment out the unsigned archive step.

Android

  1. Create the app in Play Console and upload a first build by hand.
  2. Upload your keystore under Team settings > Code signing identities, and enable the android_signing block with its reference name.
  3. Add GCLOUD_SERVICE_ACCOUNT_CREDENTIALS (secure) to the android_release group, and enable publishing.

python3 scripts/validate_yaml.py checks codemagic.yaml against the Codemagic schema twice, as shipped and with all #| blocks enabled, so the commented blocks stay valid.

Watch the gate stop a release

  1. In e2e/tests/order.e2e.ts, change an expected value, for example the order number in the confirmation check.
  2. Commit, then push a tag: git tag v0.0.1 && git push origin v0.0.1.
  3. The release workflow fails in the e2e step, the JUnit report names the failing test, and the build never reaches the release step.

Layout

  • lib/: the Flutter app. lib/semantics.dart gives every widget a stable test ID, which e2e finds with getByTestId.
  • e2e/: the tests and e2e.config.ts.
  • codemagic.yaml: the five workflows.
  • scripts/validate_yaml.py: schema check for codemagic.yaml.
  • skills/: agent skills for setting up e2e on Codemagic and running the build loop.

Building locally

flutter build ios --simulator --debug builds the app for a simulator. Xcode 27 needs an iOS deployment target of 15 or later, and Flutter 3.44 rejects its simulator framework's architecture order. The project already sets both: the target in the Xcode project and ARCHS[sdk=iphonesimulator*] = arm64 in ios/Flutter/Debug.xcconfig. The second setting suits Apple Silicon Macs only.

License

MIT. See LICENSE.

[ get started ]

your verificationlayerstarts withjust one command

npx e2e init