Playwright Configuration File Overview
Introduction
- Welcome to the Playwright with TypeScript series.
- Focus: Understanding the Playwright configuration file before scripting.
- HTML Report will be covered in the next video.
Configuration File Basics
- Playwright offers many configurable options in the configuration file.
- Configuration file often provided by default upon installation via Playwright extension or npm init command.
- Manual creation of the configuration file is required if installed manually.
File Name and Location
- Name:
playwright.config.ts
(use this specific name for Playwright to recognize and use it directly).
Creating the Configuration File Manually
- Necessary Imports:
defineConfig
: Core config structure.
devices
: List of supported devices/browsers.
- Both are imported from
@playwright/test
.
- Basic Structure:
- Export default configuration using
defineConfig
. Example syntax provided.
Key Configuration Options
testDir
- Specifies the directory to recursively scan for test files.
- Example:
{ testDir: './tests' }
means scan the 'tests' folder.
fullyParallel
- Enables parallel test execution.
- When
true
, tests within files are also parallelized.
- Important: Make tests independent to avoid failures in parallel execution.
forbidOnly
- Prevents accidental commits with
test.only
annotations by throwing errors if test.only
is detected during CI executions.
retries
- Sets the number of retries for failing tests, which can be different for local and CI environments.
- Example:
{ retries: process.env.CI ? 2 : 0 }
means 2 retries on CI, 0 locally.
workers
- Number of parallel workers used to run tests.
- Example:
{ workers: 3 }
sets three parallel workers for local runs.
- Can be specified differently for CI environments.
reporter
- Configures test reporting format (e.g., HTML, JSON, JUnit).
- Example single report:
[{ reporter: 'html' }]
.
- Example multiple reports:
[{ reporter: 'html' }, { reporter: ['json', { outputFile: 'results.json' }] }].
timeout
- Default timeout for each test in milliseconds.
- Example:
timeout: 30000
sets a 30-second timeout.
- Can be overridden specifically for
expect
assertions.
use
- Global options for all tests.
- Example:
{ use: { headless: false, trace: 'on' }}
Device Configuration
- Configuring tests for different devices (Chromium, Firefox, Webkit, mobile devices).
- Example structure for devices.
Example Code
- Basic example structures to setup various configurations.
Running and Debugging Tests
- Commands to run tests:
npx playwright test
, npx playwright test --project={projectName}
.
- Default headless mode, specify
--headed
to run in headed mode.
Additional Notes
- Configurable options are numerous beyond the primary options discussed (e.g., screenshots, video recording).
- Future videos will cover specific features in detail (e.g., HTML reports, trace viewer).
Conclusion
- Recap on getting, setting up, and using
playwright.config.ts
.
- Hands-on experience suggested to better understand each configuration option.
- Stay tuned for future videos and further details on reporting and debugging.
Please like, share, and subscribe!