When Playwright is installed, a file named playwright.config.js is created automatically. This is the central configuration file for Playwright. This file controls test behavior, base URL, browser settings, screenshots, video recordings, retries, timeouts, parallel execution, and more. Instead of configuring these options inside every test, the config file helps to define them once and use if for all the test. Let’s go through the configuration that is created by default during Playwright installation.
Default playwright.config.js, you can find this file in the root of the folder where playwright is installed.
Example plawright.config.js
Lets breakdown the configuration file and see it uses.
1. Import Statements
- defineConfig: Helps with auto-completion and validation
- devices: Provides predefined browser and device configurations
2. Test Directory
All Playwright test files should be placed inside this folder. Playwright automatically scans this directory to find tests.
3. Fully Parallel Execution
- Allows tests within the same file to run in parallel
- Improves execution speed
- Safe because Playwright isolates each test using browser contexts
4. Workers (Parallel Threads)
- CI environment: Tests run serially (1 worker)
- Local environment: Playwright uses available CPU cores
Example:
This means:
- Playwright can execute tests using 2 parallel workers
- Multiple tests may run at the same time
- Execution becomes faster for large test suites
5. Prevent test.only in CI
Fails the CI build if test.only is committed also prevents accidentally running only part of the test suite in CI.
6. Retries Configuration
This statement retries failed tests only in CI, No retries when running tests locally
7. Retry on all places
This means:
- If a test fails, it will be retried up to 2 additional times
- If it passes in a retry, it is marked as flaky
- If it fails in all retries, it is marked as failed
8. Reporter Configuration
- Generates an interactive HTML report
- Open the report using: npx playwright show-report
- In Playwright html, list, dot, line, json and junit report types are avilable. We can also configure multiple reports.
9. Shared use Options
- These settings apply to all tests and browsers
- Trace is collected only when a test fails and retries
- Trace includes screenshots, DOM snapshots, network activity, and console logs. We will cover Playwright tracing in detail in an upcoming section.
10 Base URL Configuration
baseURL allows you to write cleaner navigation code. Instead of writing full URL like await page.goto('https://qafeast.com/tools'); you can write await page.goto('/tools');
11. Browser Projects (Cross-Browser Testing)
This configuration allows the same tests to run on: Chromium (Google Chrome and MS Edge), Firefox and WebKit (Safari engine)
This makes cross-browser testing easy without duplicating test code.