πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
Back to All Questions
Question 16 of 100
Execution
Beginner

How do you run tests in parallel or in multiple browsers/devices/contexts?

The Answer

Configure `projects` in `playwright.config.ts` to run your test suite across multiple browsers and devices. Each project is an independent test run with its own browser and configuration.

Deep Dive Explanation

Playwright bundles 50+ device descriptors (phones, tablets, laptops) with correct viewport, user-agent, touch events, and device pixel ratio. Running across Chrome, Firefox, and WebKit (Safari) with one command ensures cross-browser compatibility without managing multiple browser installations.

example.spec.ts
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  fullyParallel: true,
  projects: [
    // Desktop browsers
    { name: 'Chrome',   use: { ...devices['Desktop Chrome'] } },
    { name: 'Firefox',  use: { ...devices['Desktop Firefox'] } },
    { name: 'Safari',   use: { ...devices['Desktop Safari'] } },

    // Mobile emulation
    { name: 'Mobile iOS',     use: { ...devices['iPhone 14'] } },
    { name: 'Mobile Android', use: { ...devices['Pixel 7'] } },

    // Custom viewport
    { name: 'HD', use: { viewport: { width: 1920, height: 1080 } } },
  ],
});

// Run specific project:
// npx playwright test --project=Firefox
// npx playwright test --project="Mobile iOS"