Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk6 min

Playwright Screenshot Tests on Mobile Viewports: Device Emulation Guide

A practical guide to Playwright mobile screenshot tests: choose a device preset or viewport, run browser projects, manage visual baselines, and diagnose CI mismatches.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a Playwright device preset when you want a coherent mobile-browser profile, or set the CSS viewport directly when you want to test a particular responsive breakpoint. Run those configurations as Playwright Test projects, and generate and compare visual baselines in a consistent environment. Emulation is useful for mobile layout checks; connected Android testing is a separate option when you need to validate Android Chrome or WebView on hardware.

How do I take screenshots at mobile viewport sizes in Playwright?

For repeatable visual tests, configure a mobile profile as a Playwright Test project and use expect(page).toHaveScreenshot(). A device preset supplies a bundle of browser settings; a viewport override lets you deliberately test a page width and height. You can use either, or spread a preset first and override only the values relevant to your test.

As an Amazon Associate I earn from qualifying purchases.

Use a device preset for a coherent mobile profile

Playwright provides a devices registry of descriptors for selected desktop, tablet, and mobile profiles. A descriptor may include browser-related settings such as user agent, screen and viewport dimensions, touch capability, and mobile behavior. For example, the documented Pixel 5 profile can be applied to a project like this:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  projects: [
    {
      name: 'mobile-chrome',
      use: { ...devices['Pixel 5'] },
    },
  ],
});

Device names are examples, not a promise that the registry is fixed or exhaustive. Check the registry in the Playwright version installed in your project. The preset simulates browser properties; it does not guarantee the same rendering as a physical phone.

#1 Best Overall
Sale
Motorola Moto g - 2026 | Unlocked | Made for US 4/128GB | 50MP Camera | Pantone Slipstream, Cellular_Phone
  • Universal unlocked. Compatible with all major U.S. carriers, including Verizon, AT&T, T-Mobile and other prepaid carriers.
  • Super-bright, super-smooth 6.7" display. See your screen clearly even outdoors in sunlight, and enjoy seamless views with a fast-refreshing 120Hz display.*
  • AI-powered camera system. Take stunning photos in any light with the 50MP camera**, look your best with a 32MP selfie cam*****, and capture extreme close-ups.
  • Superfast 5G performance. Unleash your entertainment at 5G speed*** with the MediaTek Dimensity 6300 chipset and up to 12GB of RAM with RAM Boost****.
  • Long-lasting battery + TurboPower charging. Power through day after day with a 5200mAh battery, then get hours of power in just minutes.****

Override the viewport when breakpoint coverage is the goal

Responsive CSS reacts to the CSS viewport, so set the viewport dimensions to the breakpoint or page size you intend to cover. You can override a preset in project options by putting your chosen value after the spread:

use: {
  ...devices['Pixel 5'],
  viewport: { width: 390, height: 844 },
}

The dimensions above are an illustrative test choice, not a universal recommended phone size. Choose dimensions from your supported layout breakpoints and user audience. Alternatively, set a page’s viewport during a test with await page.setViewportSize({ width: 390, height: 844 }). For context-level setup, pass viewport settings to browser.newContext().

Keep pixel density distinct from CSS viewport size

deviceScaleFactor controls device-pixel density, while viewport width and height describe the CSS layout area. If your test is about responsive CSS, choose the CSS viewport deliberately. Add a device scale factor only when screenshot pixel density itself matters, and keep it consistent between baseline creation and comparison.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Know what mobile emulation changes

The isMobile setting controls whether the page’s meta viewport tag is taken into account and enables touch events. A preset may already provide mobile-specific values, so avoid adding duplicate or conflicting settings without a reason. Playwright also supports emulated conditions such as locale, timezone, geolocation, permissions, and color scheme; configure only the conditions that affect the behavior under test. See the Playwright emulation guide for available options and current device descriptors.

Rank #2
Sale
Samsung Galaxy A17 5G Smart Phone 128GB US 1 Yr Manufacturer Warranty Black
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.

How should I organize desktop and mobile screenshot projects?

Projects let the same test suite run under distinct browser and device configurations. A small, intentional matrix is easier to interpret and maintain than running every possible combination. This illustrative configuration includes desktop browser engines and two mobile-emulation profiles:

import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  projects: [
    {
      name: 'desktop-chromium',
      use: { ...devices['Desktop Chrome'] },
    },
    {
      name: 'desktop-firefox',
      use: { ...devices['Desktop Firefox'] },
    },
    {
      name: 'desktop-webkit',
      use: { ...devices['Desktop Safari'] },
    },
    {
      name: 'mobile-chrome',
      use: { ...devices['Pixel 5'] },
    },
    {
      name: 'mobile-safari',
      use: { ...devices['iPhone 12'] },
    },
  ],
});

These project names and profile labels follow documentation examples and may need adjustment for the installed Playwright version. Select projects based on the browsers and layouts your product supports. The Playwright projects guide explains project configuration and selection; the browser guide covers browser engines and channels, including branded browser options.

Run all configured projects or select one

By default, Playwright Test runs the configured projects. To focus on one project, use its configured name:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
npx playwright test --project=mobile-chrome

Replace mobile-chrome with the name in your own configuration. Choose projects around meaningful risk: browser engine, supported viewport breakpoints, mobile touch or viewport behavior, and whether a branded Chrome or Edge channel is specifically needed.

Rank #3
Samsung Galaxy A16 5G 128GB Cell Phone, Unlocked Android Smartphone, Large AMOLED Display, Durable Design, Super Fast Charging, Expandable Storage, US Version, 2025, Blue Black (Renewed)
  • Charger NOT Included, 6.7" Super AMOLED FHD+, 90Hz Refresh Rate, 385 ppi, 800 nits (HBM), 1080x2340px, 5000mAh Battery
  • 128GB, 4GB RAM, microSDXC, Exynos 1330 (5nm), Octa-Core, Mali-G68 MP2 or Mali-G57 MC2 GPU
  • Rear Camera: 50MP, f/1.8 (wide) + 5MP, f/2.2 (ultrawide) + 2MP, f/2.4 (macro), LED flash, panorama, HDR; Front Camera: 13MP, f/2.0, Android 14, up to 6 major Android upgrades, One UI 6.1
  • 3G: HSDPA 850/900/1700(AWS)/1900/2100; 4G LTE: 1/2/3/4/5/7/12/13/14/20/25/26/28/29/30/38/39/40/41/48/66/71, 5G: 2/5/25/41/66/71/77/78 SA/NSA/Sub6/mmWave - Nano-SIM + eSIM
  • US Model – Global Connectivity – Compatible with Most GSM Carriers like T-Mobile, AT&T, MetroPCS, etc. Will Also work with CDMA Carriers Such as Verizon, Straight Talk.

How do screenshot baselines work?

Use Playwright Test’s toHaveScreenshot() assertion to create and compare visual references. The first run creates a baseline; later runs compare the captured image with that reference. Review the generated image and add intentional snapshots to source control through your team’s normal process.

import { test, expect } from '@playwright/test';

test('mobile home page matches its visual baseline', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveScreenshot();
});

Replace the example URL with the page under test. Playwright retries screenshot capture until two consecutive screenshots match, then stores the last capture. This reduces some transient variation, but it cannot make rendering identical across different environments.

Update snapshots only after investigating a diff

When a visual change is intentional, update references with:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
npx playwright test --update-snapshots

Inspect the resulting diffs before accepting them. A failed comparison may indicate a real product regression, an unstable page, or environmental drift. Updating snapshots reflexively can make an unintended change look like an approved baseline.

Rank #4
Sale
Samsung Galaxy A17 5G Smart Phone 128GB, US 1 Yr Manufacturer Warranty Blue
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.

Control known visual noise narrowly

Comparison options include maxDiffPixels and a custom stylesheet through stylePath, which can hide known volatile elements during capture. Scope these controls to identified sources of noise; broad hiding or generous tolerances can conceal genuine layout defects. See the visual comparisons guide for screenshot assertions, options, and baseline workflow.

Why do Playwright screenshot tests fail on CI?

A screenshot mismatch does not automatically mean the page changed. Rendering can vary with host operating system, browser version, browser settings, hardware, power source, and headless mode. The most reliable comparison is between captures made in the same environment, with matching browser and test settings. This is especially important when baselines are created on a developer laptop but checked in CI.

Common symptoms and fixes

Symptom Likely cause What to check
Small or widespread pixel differences on CI Baseline and comparison ran under different OS, browser version, settings, hardware, or headless mode. Generate and compare snapshots in a consistent environment; verify the installed Playwright browser version and run mode.
The screenshot changes between repeated runs Volatile page content or timing-dependent rendering. Inspect the page for known changing elements and use a narrowly scoped stylePath or other relevant wait condition only for identified noise.
A snapshot update clears the failure, but the change is unclear The reference may be accepting a real regression or masking environment drift. Review the image diff and determine whether the UI change is intended before updating snapshots.
The expected mobile layout does not appear The test may be using a different CSS viewport, meta-viewport behavior, or device configuration than intended. Check the project’s preset, any later viewport overrides, and whether isMobile is appropriate for the case.

For diagnoses, compare the baseline-generation setup with CI rather than assuming a particular CSS defect: confirm OS, browser build, headless setting, viewport, device scale factor, and project selection.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When is connected Android testing worth adding?

Emulated projects are the standard route for checking responsive layouts and many mobile-browser conditions. A successful emulated run is not proof that every physical device, operating-system UI, browser build, hardware characteristic, or native-app WebView will behave identically.

Best Value
Tracfone Motorola Moto G 2025, 64GB, Saphire Blue (Locked to
  • Carrier: This phone is locked to Tracfone, which means this device can only be used on the Tracfone wireless network. Tracfone plan required, activating is easy, just 3 steps.
  • DISPLAY: Immersive viewing on a 6.7-inch super-bright 120Hz display with powerful stereo speakers and Bass Boost for cinematic entertainment.
  • CAMERA SYSTEM: Advanced 50MP Quad Pixel camera captures sharp, detailed photos and videos in any lighting condition
  • PERFORMANCE: Lightning-fast 5G connectivity paired with a powerful processor and RAM Boost for smooth multitasking.
  • BATTERY LIFE: Long-lasting 5000mAh battery with TurboPower charging technology delivers hours of power in minutes.

Add connected Android automation when a product risk specifically depends on Android Chrome or WebView running on hardware. Playwright’s Android API supports discovering connected devices, launching Chrome or working with WebView, and capturing screenshots; its setup has requirements and limitations. Treat it as a separate validation path, not a prerequisite for viewport emulation. See the Playwright Android API documentation. You can follow the main emulated workflow without buying a phone.

Or skip the browser setup

If you need a screenshot of a URL rather than a Playwright visual-regression test, ScreenshotNeo is a website screenshot API and MCP server. One GET request returns a PNG, JPEG, WebP, or PDF. It is not a replacement for Playwright’s test runner or snapshot assertions.

See the ScreenshotNeo API documentation for request options. A cURL example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

Cookie banners are accepted and removed before capture, along with supported newsletter popups and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server lets AI agents use screenshot tools. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots. Sign up free for 1,000 screenshots a month, with no card required.

Frequently asked questions

Can a device preset prove that an iPhone or Android phone will match?

No. It simulates browser properties useful for testing, but does not reproduce every physical device, operating-system UI, browser build, or hardware condition.

Is a real Android device required for mobile viewport screenshots?

No. Use Playwright projects and emulation for the usual responsive screenshot workflow; connected Android automation is optional when hardware-specific Android Chrome or WebView validation matters.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.