# Test an iOS App with Mobilewright

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

Node.js >= 18, Xcode with Command Line Tools, and a booted iPhone simulator or connected real device.

## 1. Install Mobilewright[​](#1-install-mobilewright "Direct link to 1. Install Mobilewright")

```
npm install mobilewright @mobilewright/test
```

## 2. Verify your environment[​](#2-verify-your-environment "Direct link to 2. Verify your environment")

```
npx mobilewright doctor

npx mobilewright devices   # confirm your device appears
```

## 3. Initialize project config[​](#3-initialize-project-config "Direct link to 3. Initialize project config")

```
npx mobilewright init
```

This creates `mobilewright.config.ts` and an example test file.

## 4. Edit `mobilewright.config.ts`[​](#4-edit-mobilewrightconfigts "Direct link to 4-edit-mobilewrightconfigts")

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[​](#5-write-a-test "Direct link to 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[​](#6-run-the-tests "Direct link to 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[​](#test-failures "Direct link to Test failures")

When a test fails, Mobilewright automatically takes a screenshot at the point of failure and attaches it to the report.

## Next steps[​](#next-steps "Direct link to Next steps")

[Locators](https://mobilenext.ai/docs/docs/mobilewright/locators) | [Assertions](https://mobilenext.ai/docs/docs/mobilewright/assertions) | [Cloud Devices](https://mobilenext.ai/docs/docs/mobilewright/cloud-devices)
