Intermediate Chapter 8 · 8 min read

Fixtures & Configuration

Use the screen and device fixtures, override settings per-test with test.use, and master mobilewright.config options.

What Are Fixtures?

Fixtures set up the environment each test needs. Instead of writing setup and teardown code in every test, you simply declare which fixtures your test wants in its function signature — and Mobilewright prepares them for you.

The screen Fixture

The one you will use most. It gives you the device screen for finding and interacting with elements. It is scoped to each test, records a video of the test, and captures a screenshot automatically when a test fails — both are attached to the report:

screen.test.ts
import { test, expect } from '@mobilewright/test';

test('shows welcome message', async ({ screen }) => {
  // screen: find elements, act on them, take screenshots.
  // On failure, a screenshot + video land in the report automatically.
  await expect(screen.getByText('Welcome')).toBeVisible();
});
screen.test.js
const { test, expect } = require('@mobilewright/test');

test('shows welcome message', async ({ screen }) => {
  // screen: find elements, act on them, take screenshots.
  // On failure, a screenshot + video land in the report automatically.
  await expect(screen.getByText('Welcome')).toBeVisible();
});

The device Fixture

For device-level control beyond the screen: launching other apps, opening URLs, checking the foreground app. The device fixture is shared across all tests in a worker, so the device connects once and is reused — which keeps your suite fast:

device.test.ts
import { test, expect } from '@mobilewright/test';

test('launch a different app', async ({ device }) => {
  // Device-level control: launch another app and get its screen
  const screen = await device.launchApp('com.example.other');
  await expect(screen.getByText('Hello')).toBeVisible();
});

test('open a deep link', async ({ device, screen }) => {
  await device.openUrl('myapp://profile/123');
  await expect(screen.getByText('Profile')).toBeVisible();
});
device.test.js
const { test, expect } = require('@mobilewright/test');

test('launch a different app', async ({ device }) => {
  // Device-level control: launch another app and get its screen
  const screen = await device.launchApp('com.example.other');
  await expect(screen.getByText('Hello')).toBeVisible();
});

test('open a deep link', async ({ device, screen }) => {
  await device.openUrl('myapp://profile/123');
  await expect(screen.getByText('Profile')).toBeVisible();
});

Overriding Config Per-Test

Anything you set in mobilewright.config can be overridden for a single file or group with test.use(). For example, point one test file at a different app:

settings.test.ts
import { test, expect } from '@mobilewright/test';

// Every test in this file targets the settings app instead
test.use({ bundleId: 'com.example.settings' });

test('opens settings app', async ({ screen }) => {
  await expect(screen.getByText('Settings')).toBeVisible();
});
settings.test.js
const { test, expect } = require('@mobilewright/test');

// Every test in this file targets the settings app instead
test.use({ bundleId: 'com.example.settings' });

test('opens settings app', async ({ screen }) => {
  await expect(screen.getByText('Settings')).toBeVisible();
});

Configuration Options

OptionTypeDescription
platform'ios' | 'android'Target platform
deviceIdstringSpecific device ID
deviceNameRegExpDevice name pattern, e.g. /iPhone 16/
bundleIdstringApp bundle identifier
installAppsstring | string[]APK/IPA path(s) to install before launching
autoAppLaunchbooleanLaunch the app automatically after connecting (default: true)
animations'on' | 'off'Toggle system animations for stable screenshots
viewTree'on-failure' | 'off'Attach the accessibility tree to the report on failure
Tip: Turn animations: 'off' on when you take screenshots — disabling system animations makes captures pixel-stable across runs.

Mobilewright Intermediate Fixtures Config

Written by PV

© 2026 All Rights Reserved