krishworkstech.com

Importance of Playwright configuration file and its details to run the tests

The Playwright configuration file (playwright.config.ts / playwright.config.js) serves as the core of your Playwright test framework configuration. It dictates the execution of tests, the browsers/environments in which they operate, and the generation of reports/results.

playwright.config.js file  (It’s a heart of the project)

Why is the Playwright Config File Important?

  1. Centralized Control – Instead of repeating setup in every test, you define global settings once.
  2. Consistency – Ensures all tests follow the same rules (timeouts, retries, base URL, etc.).
  3. Flexibility – Allows running tests across browsers, devices, parallel workers, and environments.
  4. Scalability – Makes your test suite maintainable as it grows.

Key Details in the Config File

Here’s a breakdown of the most commonly used sections:

1. Test Directory & Timeout:

				
					testDir: './tests',       // Folder where your tests are stored
timeout: 30 * 1000,       // Max time per test (in ms)
				
			

2. Expect Config

				
					expect: {
 	 timeout: 5000           // Default timeout for assertions
}

				
			

3. Parallelism & Retries:

				
					fullyParallel: true,      // Run tests in parallel
retries: 2,               // Retry failed tests twice
workers: 4,               // Number of parallel workers
				
			

4. Reporter

				
					reporter: [
 		 ['list'],               // Console output
  ['html', { open: 'never' }], // HTML report
  ['junit', { outputFile: 'results.xml' }] // For CI tools
]

				
			

5. Base URL : Collect screenshots, videos, and traces for debugging.

				
					use: {
  baseURL: 'https://staging.myapp.com',  // Avoid repeating long URLs
  headless: true,          // Run in headless mode
  screenshot: 'only-on-failure', // Capture screenshot on failure
 		 video: 'retain-on-failure',    // Record video only on failure
  trace: 'on-first-retry'        // Collect trace for debugging
}

				
			

6. Projects (Cross-Browser/Device Testing):

				
					projects: [
 		 {
 		   name: 'Chromium',
    use: { browserName: 'chromium' },
  },
  {
    name: 'Firefox',
    use: { browserName: 'firefox' },
  },
  {
    name: 'WebKit',
    use: { browserName: 'webkit' },
  },
  {
    name: 'Mobile Safari',
 		   use: playwright.devices['iPhone 13'], // Mobile emulation
  }
]

				
			

7. Global Setup & Teardown: Useful for things like seeding databases or logging in before tests.

				
					globalSetup: './global-setup.js',
globalTeardown: './global-teardown.js',

				
			

Sample Config File

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

export default defineConfig({
  testDir: './tests',
  timeout: 30 * 1000,
  expect: {
    timeout: 5000,
  },
  fullyParallel: true,
  retries: 2,
  workers: 4,
  reporter: [
    ['list'],
    ['html', { open: 'never' }],
    ['junit', { outputFile: 'results.xml' }]
  ],
  use: {
    baseURL: 'https://staging.myapp.com',
    headless: true,
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',
    trace: 'on-first-retry',
  },
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
    {
      name: 'firefox',
      use: { ...devices['Desktop Firefox'] },
    },
    {
      name: 'webkit',
      use: { ...devices['Desktop Safari'] },
    },
  ],
});


module.exports = config;      // the configuration should availabe accross your project
				
			
  • npx playwright test > this command will find playwright.config.js file this and run the test based on this configuration.

Follow more : https://playwright.dev/docs/test-configuration

Playwright Essentials: A Step-by-Step Journey into Test Automation

Part 01: Master Playwright Testing – Framework from Scratch Guide

Part 02: How to install Playwright

Part 03: Basic Playwright Test Structure

Part 04: Importance of Playwright configuration file and its details to run the tests

Scroll to Top
  • Schematic design
  • PCB and schematic source files
  • Assembling drawing files
  • Providing prototype/sample and production PCB service
  • Testing and validation of designed hardware
  • HIPAA
  • Azure Key
  • Management
  • ES, Checksum,
  • MD5sum
  • AWS
  • Azure
  • GCP
  • DigitalOcean
  • Kotlin
  • Python
  • Tensorflow
  • Computer Vision
  • ECG
  • SPO2
  • Heart Rate
  • Glucometer
  • Blood Pressure
  • UX UI Process
  • Figma and FigJam
  • Adobe Suite
  • Selenium Java
  • Postman
  • Swagger
  • Jmeter
  • SQL
  • Java Scripter
  • Test ng
  • Extents Reports
  • Flutter
  • Java
  • Kotlin
  • Swift
  • Dart
  • React JS
  • Python
  • NodeJS
  • Django
  • HTML, CSS, JS
RDBMS
  • PostgreSQL
  • Oracle
  • MySQL
  • MariaDB
No SQL Based
  • MongoDB
  • GCP
  • FirestoreDB
  • DynamoDB
  • Azure
  • CosmosDB
  • AWS