Test an iOS App with Mobilewright
Prerequisites
Node.js >= 18, Xcode with Command Line Tools, and a booted iPhone simulator or connected real device.
1. Install Mobilewright
npm install mobilewright @mobilewright/test
2. Verify your environment
npx mobilewright doctor
npx mobilewright devices # confirm your device appears
3. Initialize project config
npx mobilewright init
This creates mobilewright.config.ts and an example test file.
4. 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,
});
5. Write a test
In example.test.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();
});
6. 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.