/mobilewright:mobilewright-write-testsfrom mobilewright
Writes Mobilewright smoke, acceptance, or regression tests for iOS/Android apps. Converts flows explored via Mobile MCP into repeatable tests and optionally sets up GitHub Actions CI.
Ships in mobilewright. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Follow the steps in order. Every command and API name below matches the mobilewright version that ships this skill.
Use it when the user wants a flow turned into repeatable Mobilewright tests, optionally running in CI. The flow is one you explored on a device with Mobile MCP, or one the user describes.
The outcome:
Check the repository with your own file tools before writing anything.
Existing Mobilewright suite. Look for mobilewright.config.ts, .js, .mts, .mjs, .cts or .cjs, and for test files that import from @mobilewright/test or mobilewright. If you find either, go to section 4.
Other UI test frameworks. Look for:
*UITests targets or directories,androidTest/ directories,.maestro/ directory or Maestro *.yaml flows,.detoxrc*,wdio.conf.* or appium in dependencies.Leave them untouched. Add Mobilewright next to them. Don't convert, move or delete any existing test.
Nothing found. This is a greenfield project. Go to section 3.
Choose where the tests live:
package.json exists at the repository root, use the root.mobile-tests/ with its own package.json, and run every command below from mobile-tests/.Use the package manager the lockfile names: package-lock.json is npm, pnpm-lock.yaml is pnpm, yarn.lock is yarn, bun.lock or bun.lockb is bun. With npm:
npm i -D mobilewright @mobilewright/test
npx mobilewright init
Install both packages. Tests import from @mobilewright/test, and installing mobilewright alone doesn't bring it in.
npx mobilewright init writes mobilewright.config.ts and example.test.ts. It skips any file that already exists. Don't use npm init mobilewright or create-mobilewright: they are interactive and overwrite the config.
Set platform and bundleId in mobilewright.config.ts:
PRODUCT_BUNDLE_IDENTIFIER in the Xcode project, or CFBundleIdentifier in Info.plist.applicationId in build.gradle or build.gradle.kts.mobile_get_foreground_app while the app is open on the device.import { defineConfig } from 'mobilewright';
export default defineConfig({
platform: 'ios',
bundleId: 'com.example.app',
deviceName: /iPhone/,
timeout: 30_000,
});
Delete example.test.ts when the real tests exist.
Before writing a test, read the config and two or three existing tests. Match what they do:
.test.ts or .spec.ts),test.describe structure,projects (platforms, devices).Never restructure, rename or "clean up" existing tests.
Walk the flow on the device with Mobile MCP first. Read each screen with mobile_list_elements_on_screen, not with screenshots.
Map each element to a locator, in this order:
| Element has | Locator |
|---|---|
an identifier (id= in text output, identifier in JSON) | screen.getByTestId('<identifier>') |
| visible text or a label | screen.getByText('<text>') or screen.getByLabel('<label>') |
| text that isn't unique on the screen | screen.getByRole('button', { name: '<text>' }) |
getByTestId matches the iOS accessibility identifier and the Android resource-id. For Android, pass the part after :id/. getByText and getByLabel match exactly; pass { exact: false } for a substring match. Roles include button, textfield, text, switch, checkbox, tab, link, header, list and listitem.
Never use coordinates. Never use Mobile MCP ref values; they last only for the current session.
If an element the test needs has no identifier and no stable text, don't write a brittle locator. Tell the user which element needs an accessibility identifier.
How to structure the tests is your call. Use the user's words ("smoke", "acceptance", "regression") and the project's conventions. There is no required tagging scheme or directory layout.
Assert on what the user sees, not on implementation details:
import { test, expect } from '@mobilewright/test';
test('signs in with email', async ({ screen }) => {
await screen.getByTestId('email').fill(process.env.TEST_USER_EMAIL!);
await screen.getByTestId('password').fill(process.env.TEST_USER_PASSWORD!, { mask: true });
await screen.getByRole('button', { name: 'Sign in' }).tap();
await expect(screen.getByText('Welcome back')).toBeVisible();
});
Locator actions: tap(), doubleTap(), longPress(), fill(text), fill(secret, { mask: true }), clear(), check(), uncheck(), swipe({ direction }), scrollIntoViewIfNeeded(). Assertions: toBeVisible(), toBeHidden(), toBeEnabled(), toHaveText(), toContainText(), toHaveValue().
Tests assume each device starts the run with no app data. In CI on Mobile Next Cloud this holds: every run gets a cleaned device, and the app is installed from installApps. On a local device it doesn't hold: the device you explored with keeps the app's data, so the user must prepare it (section 8). Don't call app.clearData() or device.clearAppData(), and don't uninstall or reinstall the app yourself.
Known limitation: Mobilewright reuses a device for several tests in a run and installs the app only once. Only the first test on each device starts with no app data, and only if the device started the run without it. A first-launch flow (onboarding, permission prompts, a first-run tutorial) is reliable only as the first test a device runs. Decide how to structure the tests around this. If the tests cover a first-launch flow, tell the user about the limitation in your final message.
process.env in tests or in the config. Never hardcode them, and never write them into any file.fill(value, { mask: true }). Without mask, the typed text appears in the test report and in the results uploaded to Mobile Next. mask needs a Mobilewright release after 0.0.70; if the project has an older one, tell the user to upgrade.mask hides the text only in step titles: a screenshot or view tree saved on failure still shows whatever the field displays.Run each new test file three times in a row, on the local device you explored with:
npx mobilewright test login.test.ts
npx mobilewright test login.test.ts
npx mobilewright test login.test.ts
All three runs must pass. A test that passes only sometimes isn't done.
A first-launch test (section 6) needs a device without app data on every run, and you must not clear it yourself. Before each of its three runs, ask the user to delete the app from the device and install it again without opening it, and wait until they confirm. The local config has no installApps, so Mobilewright launches the installed app and fails if it is missing. Run first-launch test files on their own, not together with other test files.
If a test fails because the app behaves wrongly, don't change the assertion to match the app. Report it to the user as a probable bug, with the step, the expected result and the actual result.
Never commit or push. Leave the changes in the working tree for the user.
Only if .github/workflows/ contains at least one workflow file. If .github/ exists without workflows, ask the user whether to add one. If there is no .github/, give the user the run command, npx mobilewright test, and stop. Don't write GitLab, Bitrise or CircleCI config.
If a workflow already runs mobilewright, extend it. Otherwise create .github/workflows/mobilewright.yml.
CI devices come from Mobile Next Cloud. Install the driver:
npm i -D @mobilewright/driver-mobilenext
Switch to it in the config only when MOBILENEXT_API_KEY is set, so local runs don't change:
import { defineConfig, type MobilewrightConfig } from 'mobilewright';
import { MobileNextDriver } from '@mobilewright/driver-mobilenext';
const config: MobilewrightConfig = {
platform: 'ios',
bundleId: 'com.example.app',
deviceName: /iPhone/,
viewTree: 'on-failure',
};
if (process.env.MOBILENEXT_API_KEY) {
config.driver = new MobileNextDriver();
config.deviceType = 'real';
config.installApps = ['./build/app.ipa'];
config.reporter = [['list'], ['html']];
}
export default defineConfig(config);
The app comes from the repository's existing build: a workflow job, a Fastlane lane, a script or a Gradle task. Real iOS devices need an .ipa. Android needs an .apk. Point installApps at the file that build produces. If you can't find a build, ask the user for the artifact path. Never invent signing, certificate or provisioning steps.
Use two jobs: build the app, then test on ubuntu-latest. Pin action major versions:
name: Mobilewright Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
jobs:
build:
# Pull requests from forks and Dependabot get no secrets, so there is no device to test on.
if: github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- run: ./scripts/build-app.sh # the repository's existing build; produces build/app.ipa
- uses: actions/upload-artifact@v4
with:
name: app
path: build/
test:
needs: build
if: github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')
runs-on: ubuntu-latest
timeout-minutes: 30
env:
MOBILENEXT_API_KEY: ${{ secrets.MOBILENEXT_API_KEY }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: app
path: build/
- uses: actions/setup-node@v4
with:
node-version: 24
- run: npm ci
- run: npx mobilewright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: mobilewright-report
path: |
mobilewright-report/
test-results/
retention-days: 30
Adjust it to the project:
Install with the package manager the lockfile names, as in section 3:
| Lockfile | Setup step | Install command |
|---|---|---|
package-lock.json | actions/setup-node@v4 | npm ci |
pnpm-lock.yaml | pnpm/action-setup@v4, then actions/setup-node@v4 | pnpm install --frozen-lockfile |
yarn.lock | actions/setup-node@v4 | yarn install --immutable (Yarn 2+) or yarn install --frozen-lockfile (Yarn 1) |
bun.lock or bun.lockb | oven-sh/setup-bun@v2 | bun install --frozen-lockfile |
Run the tests with the same manager: pnpm exec mobilewright test, yarn mobilewright test or bunx mobilewright test.
Replace the build step with the repository's real build. If a workflow already builds the app, reuse its artifact instead of building again.
Tests in mobile-tests/: set defaults.run.working-directory: mobile-tests on the test job. Paths in the config resolve from the config's directory, so installApps becomes '../build/app.ipa', and the report paths to upload become mobile-tests/mobilewright-report/ and mobile-tests/test-results/.
Add every login variable from section 7 to the test job's env, from secrets.
Don't turn on video recording. Failure screenshots are always captured.
There is no emulator fallback. The workflow requires MOBILENEXT_API_KEY. GitHub doesn't pass secrets to pull requests from forks or from Dependabot, so keep the if: on both jobs, or on the test job when you reuse an existing build: it skips the tests on those pull requests instead of failing them. Tell the user to create an API key at mobilenext.ai and add it as a repository secret named MOBILENEXT_API_KEY.
Set reporters in the config, never with --reporter on the command line. The command-line flag replaces every configured reporter, including the one that uploads results to Mobile Next.
End with this checklist:
npx mobilewright test),MOBILENEXT_API_KEY and every login variable,| Mistake | Do instead |
|---|---|
Tapping coordinates, or using a Mobile MCP ref | getByTestId, then getByText / getByLabel, then getByRole (section 5) |
| Changing an assertion until the test passes | Report a probable app bug (section 8) |
Calling app.clearData() or clearAppData(), uninstalling or reinstalling the app | Ask the user to delete the app and install it again (section 8) |
Hardcoding a password, or writing it to .env | Read it from process.env (section 7) |
fill(password) without mask | fill(password, { mask: true }) (section 7) |
npx mobilewright test --reporter ... in CI | Set reporter in the config; the flag drops the Mobile Next upload |
npm ci in a pnpm, Yarn or Bun repository | The lockfile's install command (section 9) |
Removing the if: from the CI jobs | Keep it; fork and Dependabot pull requests get no secrets |
| Committing or pushing | Leave changes in the working tree |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub mobile-next/mobilewright --plugin mobilewrightOther plugins' skills for the same job