Test an iOS App with Mobilewright
Prerequisites
Node.js 22.12 or newer, Xcode with Command Line Tools, and a booted iPhone simulator or connected real device.
1. Create a project
npm init mobilewright@latest
The CLI walks you through setup and creates a ready-to-run project: mobilewright.config.ts, tests/example.spec.ts and package.json.
Adding Mobilewright to an existing project instead? Run npm install mobilewright, then npx mobilewright init to add a config and an example test to the current directory.
2. Verify your environment
npx mobilewright doctor
npx mobilewright devices # confirm your device appears
The first time you run a test on iOS (simulator or real device), run npx mobilewright install to set up the agent on the device.
3. Edit mobilewright.config.ts
Set your app's bundle ID:
import { defineConfig } from 'mobilewright';
export default defineConfig({
platform: 'ios',
bundleId: 'com.example.myapp',
timeout: 10_000,
});
4. Write a test
In tests/example.spec.ts:
import { test, expect } from '@mobilewright/test';
test('can sign in', async ({ device, screen, bundleId }) => {
await device.terminateApp(bundleId).catch(() => {});
await device.launchApp(bundleId);
await screen.getByLabel('Email').fill('user@example.com');
await screen.getByLabel('Password').fill('password123');
await screen.getByRole('button', { name: 'Sign In' }).tap();
await expect(screen.getByText('Welcome back')).toBeVisible();
});
5. Run the tests
npx mobilewright test
Optional flags:
npx mobilewright test --reporter html # generate HTML report
npx mobilewright test --retries 2 # retry flaky tests
npx mobilewright show-report # open HTML report
Test failures
When a test fails, Mobilewright automatically takes a screenshot at the point of failure and attaches it to the report.
Next steps
Was this page helpful?