Run Your First Desktop and Mobile Browser Check with Playwright

Run a small saved-places fixture, verify both an included and an excluded result, and capture a browser screenshot.

This check tests a browser feature at desktop and phone widths. It uses a small HTML fixture with no account, network dependency after download or external data. Selecting Parks should reveal Riverside Park, hide Corner Café and report 1 place shown. Checking all three catches a filter that only updates its count or only changes the visible list.

The Parks filter and one result visible in a desktop-width browser
Chromium at 1280 px.
The same Parks fixture in a narrow browser with Riverside Park visible
Chromium at 390 px.

Set up the example

Create an empty project and install Playwright Test. Download the fixture into the same directory.

npm init -y
npm install -D @playwright/test
npx playwright install chromium
curl -fL https://www.open-auto-glm.com/examples/filter-places.html -o filter-places.html

From that folder run python3 -m http.server 8000 --bind 127.0.0.1 in a separate terminal. Open http://127.0.0.1:8000/filter-places.html once to confirm that the fixture is being served. If that port is already in use, choose a different one in both the server and test.

Check the result at both widths

Use the same browser assertion twice
  1. Set the fixture

    Open the local saved-places page with its known starting items.

  2. Select Parks

    Apply the same filter in desktop and narrow browser contexts.

  3. Inspect both outputs

    Verify that the visible cards match the filter before comparing layout.

Save this as filter.spec.js and run npx playwright test filter.spec.js.

const { test, expect } = require('@playwright/test');

for (const width of [1280, 390]) {
  test(`Parks filter at ${width}px`, async ({ page }, testInfo) => {
    await page.setViewportSize({ width, height: 800 });
    await page.goto('http://127.0.0.1:8000/filter-places.html');
    await page.getByRole('combobox', { name: 'Category' }).selectOption('Parks');
    const list = page.getByRole('list', { name: 'Places' });
    await expect(list.getByText('Riverside Park')).toBeVisible();
    await expect(list.getByText('Corner Café')).toBeHidden();
    await expect(page.getByRole('status')).toHaveText('1 place shown');
    await page.screenshot({ path: testInfo.outputPath('parks.png') });
  });
}

Playwright’s locator guide describes accessible names and automatic waiting. Inspect the captured screenshot when the viewport changes, then change the test to select Cafés and invert the assertions. Avoid fixed screen coordinates. This example covers the browser DOM and layout. A native app, operating system prompt or actual mobile browser capability needs its own test target. Use the system comparison to choose one.