How do I configure Playwright tests to run with iPhone 14 emulation?


To run tests with iPhone 14 emulation in @playwright/test, you can set device parameters in the test file or the configuration file. Playwright provides a registry of device parameters for popular mobile devices, including iPhone 14.

In the Test File

Use the test.use() method to set the viewport size and other device parameters for a specific test:

import { test } from '@playwright/test';
import devices from 'playwright-core/lib/server/deviceDescriptors';

  ...devices['iPhone 14'],

This sets the device parameters to match iPhone 14 for the test.

In the Configuration File

Configure device parameters globally in the playwright.config.ts file:

import { defineConfig } from '@playwright/test';
import devices from 'playwright-core/lib/server/deviceDescriptors';

export default defineConfig({
  use: {
    ...devices['iPhone 14'],
    // other global options

This sets all tests to run with iPhone 14 emulation by default.

Remember to consider factors like touch events and geolocation when emulating a mobile device. Enable touch events by setting isMobile to true in your configuration or test options. To change geolocation for all pages within a context, use context.setGeolocation().

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.