Blog Details Shape
Automation testing

Using Playwright for Mobile Web Testing: Best Practices and Tips

Published:
July 18, 2025
Table of Contents
Join 1,241 readers who are obsessed with testing.
Consult the author or an expert on this topic.

Ever spend hours debugging mobile web tests only to have them fail in production? Join the club. What works flawlessly on your desktop can turn into a nightmare on mobile browsers.

As mobile web usage continues to rise, ensuring your site performs well across all devices is more important than ever, driving the need for robust mobile testing solutions.

But here’s the thing: Playwright for mobile web testing changes everything. With its cross-browser capabilities and device emulation, you can finally stop the endless cycle of “works on my machine” excuses.

I’ve been there—fighting with viewport issues, touch events, and those frustrating orientation bugs. After helping dozens of teams implement reliable mobile test suites, I’ve collected the approaches that actually work.

What most developers miss about mobile testing isn’t technical—it’s strategic. And that’s exactly what we’ll uncover next.

Mobile Web Testing with Playwright

1. Why Mobile Web Testing is Crucial?

More than half of global web traffic comes from mobile devices. Your web application must function flawlessly on smartphones and tablets.

Users expect a fast, responsive, and interactive experience across all devices. Poor mobile web performance can lead to frustrated users, lower engagement, and ultimately lost revenue.

Effective mobile testing is essential to ensure your application meets user expectations and maintains high engagement.

2. Benefits of Using Playwright for Mobile Testing

Playwright is a modern test automation framework for end-to-end testing. It simplifies testing across mobile browsers and devices. The key benefits include:

  • Cross-browser support (Chromium, Firefox, WebKit).
  • Device emulation for testing various screen sizes and resolutions.
  • Touch gestures and network condition emulation for realistic mobile tests.
  • Parallel execution to speed up test runs across multiple devices.
  • Enhanced testing efficiency by optimizing test execution and reducing flakiness, leading to faster and more reliable automated mobile web testing.

By using Playwright, you can ensure that your application delivers the same high-quality experience to mobile users, whether on Android, iOS, or desktop browsers.

Why Playwright is Ideal for Mobile Testing

One of the reasons Playwright has become so popular for mobile web testing is its comprehensive support for device emulation, cross-browser compatibility, and realistic user interaction simulation — all of which help teams deliver mobile experiences without the hassle of managing dozens of physical devices.

Playwright excels in mobile automation by allowing teams to simulate mobile environments, emulate real devices, and seamlessly integrate these processes into broader testing strategies for improved efficiency and device coverage.

1. Device Emulation

Playwright comes with an extensive library of built-in device descriptors that make it super easy to emulate popular smartphones such as iPhone 12, Pixel 5, or Galaxy S20 Ultra.

By using these pre-configured settings, you can instantly emulate mobile devices by configuring device viewports, user agent strings, and device-specific features like device scale factor and touch capabilities.

So your QA team or developers don’t have to manually configure viewport sizes or guess how a site might look on different devices — the framework does the heavy lifting for you.

This level of emulation allows you to quickly switch contexts and verify that your web application’s layout, responsiveness, and interactive elements work perfectly across a wide range of mobile screens.

Playwright is especially useful for responsive design testing, as it enables you to efficiently verify responsive designs across various devices and screen sizes.

2. Cross-Browser Testing

In the real world, your users are not just using a single browser engine; they’re browsing on different browsers and web browsers like Chrome for Android, Safari for iOS, or other niche mobile browsers.

Playwright makes this cross-browser testing easy by supporting Chromium, WebKit, and Firefox out of the box. With this multi-browser engine capability, you can catch rendering differences, layout shift, or functionality issues that might otherwise slip through if you were only testing on one browser family.

Whether it’s the latest version of Chrome on a Pixel device or Safari on an iPhone, you can be sure your tests cover the full spectrum of environments your users use every day. 

Playwright also enables you to test web applications across various devices, ensuring comprehensive coverage and consistent performance on both mobile and desktop platforms.

3. Real User Simulation

Beyond just adjusting the viewport to mimic a mobile device, Playwright goes further by providing a real user simulation that mirrors how people interact with web applications on touchscreens.

It supports complex gestures like taps, long presses, swipes, and even pinch-to-zoom, so your app’s touch-based interactions behave naturally. This is especially valuable for mobile-first designs that rely heavily on swipe menus, drag-and-drop features, or touch-driven animations.

By simulating these interactions, Playwright helps you uncover bugs that only occur when users interact with your site through real gestures, so you can be confident your mobile user experience is smooth, intuitive, and ready for production.

Additionally, Playwright enables comprehensive testing of diverse mobile scenarios, ensuring your application performs reliably across different devices and environments.

{{cta-image}}

Importance of Playwright mobile testing

Playwright is great for mobile web testing because of its native mobile emulation capabilities, cross-browser testing, and network condition emulation. 

With Playwright's built-in, native mobile emulation, you can accurately replicate various mobile environments directly within web browsers, eliminating the need for third-party tools.

Not only can you test your application as you change the screen size, resolution, or touch interaction, supporting responsive web design and cross-browser compatibility, but it will even simulate a few devices like The Pixel 5, The iPhone 12, and The Samsung Galaxy S20.

After device emulation, Playwright uses the real browser input pipeline to simulate real user interactions, including touching and swiping, for more accurate results by testing in realistic mobile environments.

  • Cross-browser coverage across Chromium, Firefox, and WebKit provides total coverage on mobile browsers. Playwright is designed to work seamlessly with modern browsers, supporting advanced web features.
  • One unified API with device emulation—no additional SDKs or complex device labs.
  • Automatic waits automatically smooth out slow or unstable mobile networks. Playwright can produce trusted events on dynamic controls, ensuring interactions behave as they would for a real user.
  • Built-in retry logic handles flaky taps, swipes, and gestures.
  • Parallel execution can hit many device/viewport combos simultaneously.
  • Also, keep in mind: these are emulated devices—do sanity checks on real hardware and real user devices before you release to ensure authentic results.

Testing across different mobile environments is essential for comprehensive coverage and reliable mobile web experiences.

{{blog-cta-1}}

Key Techniques for Playwright Mobile Testing

Setting Up a Playwright Mobile Testing

To set up Playwright for mobile testing, you will need to install Playwright, set up mobile viewports or connect to real devices, and then write your tests.

Mobile device emulation tests are typically written and executed in a dedicated test file, which contains the test cases and configurations for validating responsive design and device-specific behavior.

Here are the steps that’ll show you how you can set up playwright mobile testing:

1. Installation and dependencies

Getting started with Playwright for mobile testing is pretty simple. First, install Playwright using npm:

npm init playwright@latest’
Copied!

This command sets up everything you need. If you’re adding it to an existing project, you can install just the package:

npm install -D @playwright/test
# Install browsers
npx playwright install

Copied!

2 . Basic Configuration Setup

Now that you have Playwright installed, let’s configure it for mobile testing. You can customize the configuration based on your testing needs, such as viewport sizes, device configurations, and timeouts.

Here’s an example of how to set up Playwright for mobile testing:

import { defineConfig } from '@playwright/test';
‍
export default defineConfig({
  projects: [
    {
      name: 'Mobile Chrome',
      use: {
        browserName: 'chromium',
        ...devices['Pixel 5'],
      },
    },
    {
      name: 'Mobile Safari',
      use: {
        browserName: 'webkit',
        ...devices['iPhone 12'],
      },
    },
  ],
});

Copied!

3. Device Emulation Setup

Playwright makes device emulation dead simple with its built-in device list. Import the devices collection:

import { devices } from '@playwright/test';
This collection includes popular mobile devices with preset configurations. Want to test on an iPhone 13? Galaxy S8? No problem:
test.use({ ...devices['iPhone 13'] });
// or
test.use({ ...devices['Galaxy S8'] });
You can also create custom device profiles for specific testing needs:
const myCustomPhone = {
  viewport: { width: 375, height: 667 },
  deviceScaleFactor: 2,
  isMobile: true,
  hasTouch: true,
  userAgent: 'Custom User Agent String'
};
test.use(myCustomPhone);

Copied!

4. Viewport and user agent configuration

Sometimes you need to adjust viewport settings on the fly. Here's how:

test('test on different viewport', async ({ page }) => {
  await page.setViewportSize({ width: 390, height: 844 });
  // your test code
});

Copied!

User agent strings are crucial for proper device detection:

test('with custom user agent', async ({ browser }) => {
  const mobileUserAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X)';
  const context = await browser.newContext({
    userAgent: mobileUserAgent
  });
  const page = await context.newPage();
  // continue with test
});

Copied!

{{cta-image-second}}

Writing Your First Mobile Test

To create mobile tests efficiently, you need to understand mobile-specific interactions and behaviors.

With Playwright mobile devices, you can emulate different screen sizes, device profiles, and touch interactions, enabling comprehensive testing across a wide range of mobile environments.

1. Mobile-Specific Interactions

Mobile testing is different from desktop testing. The main difference is touch interactions (e.g., tap, swipe, pinch) instead of mouse clicks. Playwright makes it easy to simulate these interactions to mimic real user behavior on mobile devices.

For instance:

  • Taps: Replace mouse clicks with the tap() method.
  • Swipes: Use the swipe() method to simulate swiping gestures.
  • Pinch-to-zoom: Simulate pinch gestures with the pinch() method.

It's also important to handle browser tabs during mobile testing, especially when links open in new tabs, to ensure all tab transitions and related interactions are tested.

For your first mobile test, you want to ensure basic functionality like using the page load method to see if your mobile page loads properly, mobile navigation, and touch interactions, and now you have a baseline for more complex mobile testing scenarios.

2. Example Code for Mobile Test:

const { test, expect, devices } = require('@playwright/test');
‍
test.describe('Mobile Web Tests', () => {
test.use({ ...devices['Galaxy S20 Ultra'] });
‍
test('Alpha_E2E_01 - login to logout', async () => {
  await page1.goto('http://demo.alphabin.co');
  await expect(page1).toHaveTitle(`AB Demo Store`);
  await page1.locator(`input[name="email"]`).click({ force: true });
  await page1.locator(`input[name="email"]`).fill(email);
  await page1.locator( `input[name="password"]`).click({ force: true });
  await page1.locator( `input[name="password"]`).fill(password);
  await page1.locator( `//button[normalize-space()='Sign in']`).click({ force: true });
  await page1.locator(`//p[normalize-space()='Log Out']`).click({ force: true });
  await page1.close();
})

Copied!

Running Mobile Tests: Three Approaches

1. Real, physical Android and iOS Devices

While Playwright primarily focuses on browser automation, you can connect it to real devices using tools like Appium or by running tests against mobile browsers directly.

You can use Android Debug Bridge (ADB) to connect and automate real Android devices and emulators, enabling accurate mobile testing environments.

For basic mobile web testing, you can run Playwright tests on actual devices by:

  • Setting up a mobile browser on your device
  • Connecting to your development server
  • Running tests against the mobile browser

This approach gives you the most accurate results, but requires more setup and maintenance

Example for Running Tests on Real Devices:

test.use({
  browserName: 'chromium',
  device: 'Pixel 5', // Specify the real device name
  deviceConnection: {
    username: 'your-username',
    accessKey: 'your-access-key',
  }
});
‍
test('Test on Real Device', async ({ page }) => {
  await page.goto('`https://demo.alphabin.co/`);
  // Perform your test steps on a real device
  await expect(page).toHaveTitle('Your Page Title');
})

Copied!

2. Simulators and Emulators

Playwright’s built-in device emulation acts as a simulator, providing a good balance between accuracy and convenience. The WebKit browser that Playwright uses for iOS testing is very close to actual Safari behavior.

Playwright can also emulate different Android browsers by customizing viewports and user agents in your testing scripts, allowing you to test across a range of Android browser versions and devices.

For Android testing, Playwright uses Chromium, which is very similar to Chrome on Android devices. This approach works for most testing scenarios and is much faster than using real devices.

Example for Running Tests on Android Emulator:

test.use({
  browserName: 'chromium',
  device: 'Pixel 5', // Specify the emulator device
  viewport: { width: 393, height: 851 },
  isMobile: true,
  hasTouch: true,
});
‍
test('Test on Android Emulator', async ({ page }) => {
  await page.goto(`https://demo.alphabin.co/`);
  // Test mobile behaviors such as navigation and gestures
  await expect(page).toHaveTitle('Your Page Title');
});

Copied!

3. Browser Viewports

The simplest approach is to use browser viewports configured for mobile sizes. This is what most Playwright mobile testing actually does:

// Configure for mobile viewport
test.use({
  viewport: { width: 375, height: 667 },
  userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X)       AppleWebKit/605.1.15',
  deviceScaleFactor: 2,
  isMobile: true,
  hasTouch: true,
});

Copied!

This approach is fast, reliable, and catches most mobile-specific issues. It's perfect for continuous integration environments where you need quick feedback.

If you want to explore more, you can go through this video - Playwright Mobile Testing — Android & iOS Execution Demo

Best practices for playwright mobile testing

Best Practices for Mobile Playwright Testing

1. Test stability and reliability 

Mobile networks can be unstable, so it’s essential to use robust waiting strategies and error handling for reliable tests. Make sure to use Playwright's auto-wait feature to ensure elements are ready for interaction.

// Stable mobile testing practices
test('Handles Network Delays', async ({ page }) => {
  await page.goto('/slow-loading-page');
  await page.waitForLoadState('networkidle');
  await expect(page.locator('.content')).toBeVisible();
});

Copied!

2. Performance Optimization

Mobile tests should run quickly to provide fast feedback. Here are optimization strategies:

  • Parallel Testing:
// In playwright.config.js
export default defineConfig({
  workers: process.env.CI ? 2 : 4,
  projects: [
    { name: 'Mobile Chrome', use: { ...devices['Pixel 5'] } },
    { name: 'Mobile Safari', use: { ...devices['iPhone 12'] } },
  ],
});

Copied!
  • Efficient Test Structure:
test.describe('Mobile App', () => {
  test.beforeEach(async ({ page }) => {
    await page.goto(`https://demo.alphabin.co/`);
    await page.waitForLoadState('networkidle');
  });
‍
  test('navigation works', async ({ page }) => {
    // Test navigation
  });
‍
  test('forms work', async ({ page }) => {
    // Test forms
  });
});

Copied!

3. Cross-Browser Compatibility

Different mobile browsers can behave differently. Test across multiple browsers:

export default defineConfig({
  projects: [
    {
      name: 'Mobile Chrome',
      use: { ...devices['Pixel 5'] },
    },
    {
      name: 'Mobile Safari',
      use: { ...devices['iPhone 12'] },
    },
    {
      name: 'Mobile Firefox',
      use: { 
        ...devices['Pixel 5'],
        browserName: 'firefox',
      },
    },
  ],
});

Copied!

Tips for effective playwright mobile testing

  • Device Strategy: Emulation is handy for viewport and user agent checks, but it should be used together with real device testing for the most accurate.
  • Optimization Tips: Call page.waitForLoadState(‘networkidle’) to wait for 2.5, plus add custom wait techniques for slower mobile networks.
  • Auto-Wait for Flaky Tests: Use Playwright’s auto-wait option to ensure that your test waits for elements to be ready for the next interaction. This lets you free yourself from having to remember wait timings (and fails due to timing)
  • Touch First and Professional UI Behavior:  Start with testing touch interactions/test touch screen devices instead of a mouse event. Do not forget to use Playwright assertions to test reliability with dynamic content.
  • Viewport Width Variability: Testing all kinds of viewport widths instead of just the popular phones. If you can run tests in parallel, you can mitigate some question marks on performance & time taken to test.
  • Battery Performance: Track CPU & memory usage to performance specific to mobile devices, especially if a limitation to battery is expected.

Conclusion

Playwright mobile testing is a useful option for mobile web app testing. It has device emulation, cross-browser capability, and mobile-related features - all through a single API. 

While Playwright can do an excellent job simulating an Android device for responsive design and cross-browser testing, real device testing is needed for critical user journeys.

At Alphabin, we advocate a hybrid approach that combines Playwright’s emulation with real device validation, performance monitoring, and CI/CD integration. You can explore our GitHub repository, and you can use our code for your reference.

Using our proprietary tools, TestGenX and Testdino, we speed up test case generation and deliver AI-driven insights to enhance your testing process. TestGenX automates Playwright test creation, while Testdino offers actionable analytics to identify and address issues efficiently.

Mobile testing is an evolving process. Start with emulation for core functionality, expand with cross-browser tests, and improve with real device validation and performance monitoring. Alphabin helps you navigate this process seamlessly, ensuring your mobile apps perform at their best.

FAQs

1. Can I run Playwright mobile tests on real Android and iOS devices?

Yes, we can — you just need to use the config shown in the “Real Physical Device” topic. Playwright supports running tests on real Android and iOS devices by connecting to them through remote debugging or configuring them within your test setup, ensuring accurate mobile testing in real environments.

2. Is playwright good for mobile testing?

Yes, Playwright is excellent for mobile testing. It supports device emulation, all major browser engines (including iOS Safari via WebKit), and provides trace and video recording for easy debugging.

3. How can I configure tests to run on a real Android device? Can I perform mobile website testing?

Add device descriptor(s) to your playwright.config, run tests against critical iPhone/Android profiles, throttle the networks, and add the suite to CI. Finally, do a smoke run on a physical device or through a cloud for completeness.

4. Can I execute Playwright mobile tests on a simulator (iOS) and emulator (Android)?

Yes, you can execute Playwright mobile tests on both iOS simulators and Android emulators. You just need to set the appropriate device settings like viewport, user agent, and touch support in your playwright.config.ts to mimic the target device.

5. Can Alphabin help set custom device farms for our Playwright mobile tests?

Yes, Alphabin can help set up custom device farms for your Playwright mobile tests. We assist in configuring on-premise infrastructure and enable real device execution through WebSocket endpoints.

Something you should read...

Frequently Asked Questions

FAQ ArrowFAQ Minus Arrow
FAQ ArrowFAQ Minus Arrow
FAQ ArrowFAQ Minus Arrow
FAQ ArrowFAQ Minus Arrow

Discover vulnerabilities in your  app with AlphaScanner 🔒

Try it free!Blog CTA Top ShapeBlog CTA Top Shape
Discover vulnerabilities in your app with AlphaScanner 🔒

About the author

Pratik Patel

Pratik Patel

Pratik Patel is the founder and CEO of Alphabin, an AI-powered Software Testing company.

He has over 10 years of experience in building automation testing teams and leading complex projects, and has worked with startups and Fortune 500 companies to improve QA processes.

At Alphabin, Pratik leads a team that uses AI to revolutionize testing in various industries, including Healthcare, PropTech, E-commerce, Fintech, and Blockchain.

More about the author
Join 1,241 readers who are obsessed with testing.
Consult the author or an expert on this topic.
Pro Tip Image

Pro-tip

Tips for effective playwright mobile testing

  • Device Strategy: Emulation is handy for viewport and user agent checks, but it should be used together with real device testing for the most accurate.
  • Optimization Tips: Call page.waitForLoadState(‘networkidle’) to wait for 2.5, plus add custom wait techniques for slower mobile networks.
  • Auto-Wait for Flaky Tests: Use Playwright’s auto-wait option to ensure that your test waits for elements to be ready for the next interaction. This lets you free yourself from having to remember wait timings (and fails due to timing)
  • Touch First and Professional UI Behavior:  Start with testing touch interactions/test touch screen devices instead of a mouse event. Do not forget to use Playwright assertions to test reliability with dynamic content.
  • Viewport Width Variability: Testing all kinds of viewport widths instead of just the popular phones. If you can run tests in parallel, you can mitigate some question marks on performance & time taken to test.
  • Battery Performance: Track CPU & memory usage to performance specific to mobile devices, especially if a limitation to battery is expected.

Blog Quote Icon

Blog Quote Icon

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Speed up Playwright tests with TestGenX!Unlock AI-powered testing with Testdino!
Blog Newsletter Image

Don’t miss
our hottest news!

Get exclusive AI-driven testing strategies, automation insights, and QA news.
Thanks!
We'll notify you once development is complete. Stay tuned!
Oops!
Something went wrong while subscribing.