1. Introduction to Playwright TypeScript Configuration
Configuration is an important part of every automation testing framework. A well-organized configuration helps QA engineers control test execution, browser settings, timeouts, retries, reporting, and debugging from a central location.
Playwright is an open-source automation testing framework developed by Microsoft. It supports Chromium, Firefox, and WebKit browsers and provides a built-in test runner for end-to-end testing.
When developing automation projects using TypeScript, Playwright uses a configuration file called playwright.config.ts.
The playwright typescript config file allows automation engineers to define how test scripts should execute without repeating settings inside individual test cases.
For example, instead of specifying browser settings, application URLs, and timeout values in every test, you can configure them centrally.
In this tutorial, you will learn how to create and configure playwright.config.ts from scratch. We will also cover browser projects, environment variables, authentication, retries, reports, screenshots, videos, traces, and CI/CD integration.
This guide is useful for freshers, QA Automation Engineers, developers, and SDETs who want to build maintainable test automation frameworks in 2026.
2. What Is playwright.config.ts?
playwright.config.ts is the main configuration file used by the Playwright Test Runner.
It defines the settings required to execute automated test scripts.
Whenever you execute a command such as:
npx playwright test
Playwright automatically searches for its configuration file in the project directory.
The test runner reads the configuration and applies the defined settings during execution.
Important Responsibilities
- Define the test directory.
- Configure browser types.
- Set execution timeouts.
- Control parallel execution.
- Configure retry mechanisms.
- Set application base URLs.
- Manage authentication states.
- Generate HTML and other reports.
- Capture screenshots, videos, and traces.
- Configure different environments.
Why Is Configuration Important?
Consider an e-commerce application that needs to be tested across Chrome, Firefox, and Safari-compatible browser engines.
Without centralized configuration, maintaining browser settings across multiple test files becomes difficult.
With Playwright Configuration, you can define browser projects once and execute your tests across all configured browsers.
This improves maintainability and supports consistent QA engineering practices.
3. Prerequisites and Project Setup
Before creating a configuration file, install the necessary tools.
| Requirement | Purpose |
| Node.js | Runs JavaScript and TypeScript tooling |
| npm | Manages project dependencies |
| Visual Studio Code | Code editor |
| Playwright | Browser automation and test runner |
| TypeScript | Type-safe programming |
Step 1: Install Node.js
Download the LTS version from:
Verify the installation:
node -v
npm -v
Step 2: Create a Playwright Project
Open the terminal and execute:
mkdir playwright-config-project
cd playwright-config-project
Initialize Playwright:
npm init playwright@latest
Select the following options:
- Language: TypeScript
- Test folder: tests
- GitHub Actions: Yes, if required
- Install browsers: Yes
The installer creates the configuration file and sample test files automatically.
Step 3: Verify Installation
npx playwright –version
Install browsers if they are not already installed:
Your project is now ready for Playwright Test Configuration.
4. Create and Understand playwright.config.ts
The Playwright installer creates a default playwright.config.ts file.
You can modify this file according to your project requirements.
Let’s start with a simple configuration.
Basic Configuration Example
import { defineConfig } from ‘@playwright/test’;
export default defineConfig({
testDir: ‘./tests’,
timeout: 30000,
retries: 0,
workers: 2,
use: {
baseURL: ‘https://example.com’,
headless: true
}
});
Explanation
testDir: Specifies where Playwright should search for test files.
timeout: Defines the maximum execution time for an individual test.
retries: Specifies how many times a failed test should be retried.
workers: Controls the number of parallel worker processes.
use: Defines shared browser and context settings.
baseURL: Specifies the application’s base URL.
headless: Runs the browser without displaying its graphical interface.
This is a simple playwright typescript config example suitable for beginners.
5. Configure Test Directory, Timeout, Retries, and Workers
A real-world automation framework needs proper execution settings.
Let’s understand the important configuration options.
Configure Test Directory
By default, you can store test scripts inside the tests folder.
testDir: ‘./tests’,
For a larger project, you can organize tests into separate folders:
tests/
login/
login.spec.ts
dashboard/
dashboard.spec.ts
checkout/
checkout.spec.ts
Configure Test Timeout
Timeout defines how long Playwright waits for a test to finish.
timeout: 30000,
The value is specified in milliseconds.
For example, 30000 represents 30 seconds.
You can also configure assertion timeouts separately:
expect: {
timeout: 5000
},
Configure Retries
Retries help identify intermittent failures.
retries: process.env.CI ? 2 : 0,
This configuration retries failed tests twice in CI environments while keeping local execution free from automatic retries.
Retries should not be used to hide genuine application defects.
Configure Parallel Workers
workers: process.env.CI ? 1 : undefined,
fullyParallel: true,
This allows independent tests to execute in parallel locally, while CI execution starts with one worker for stability.
You can increase the CI worker count after evaluating the available resources.
6. Configure Browsers and Multiple Projects
Playwright supports three major browser engines:
- Chromium
- Firefox
- WebKit
You can configure all three through browser projects.
Multiple Browser Configuration
import {
defineConfig,
devices
} from ‘@playwright/test’;
export default defineConfig({
projects: [
{
name: ‘chromium’,
use: {
…devices[‘Desktop Chrome’]
}
},
{
name: ‘firefox’,
use: {
…devices[‘Desktop Firefox’]
}
},
{
name: ‘webkit’,
use: {
…devices[‘Desktop Safari’]
}
}
]
});
Each project executes the same test suite using a different browser configuration.
Browser-Specific Configuration
You can also override settings for an individual project.
projects: [
{
name: ‘chromium’,
use: {
…devices[‘Desktop Chrome’],
viewport: {
width: 1920,
height: 1080
}
}
}
]
This is useful when your application needs desktop and mobile browser testing.
Remember that Playwright’s WebKit project tests the WebKit engine; it does not require an installed copy of branded Safari.
7. Configure Base URL, Environment Variables, and Authentication
In professional automation projects, the application URL may change between development, QA, staging, and production environments.
Instead of hard-coding URLs inside test scripts, use environment variables.
Step 1: Install dotenv
npm install -D dotenv
Step 2: Create Environment Files
Create a .env file:
BASE_URL=https://example.com
For actual projects, create separate environment files when necessary and avoid committing secrets to Git.
Step 3: Configure Environment Variables
At the beginning of playwright.config.ts, load the environment file:
import dotenv from ‘dotenv’;
dotenv.config();
Then configure the base URL:
use: {
baseURL: process.env.BASE_URL,
headless: true
}
Now your test scripts can navigate using relative URLs:
await page.goto(‘/’);
Configure Authentication State
Playwright supports saving authentication state so that tests can reuse an authenticated session.
For example:
projects: [
{
name: ‘setup’,
testMatch: /.*\.setup\.ts/
},
{
name: ‘chromium’,
use: {
…devices[‘Desktop Chrome’],
storageState: ‘playwright/.auth/user.json’
},
dependencies: [‘setup’]
}
]
The setup project should create playwright/.auth/user.json after successful authentication.
Add the authentication folder to .gitignore because storage state can contain sensitive cookies and tokens.
This approach reduces repeated login operations in suitable test scenarios.
8. Configure Reporters, Screenshots, Videos, and Traces
Reporting and debugging are essential parts of automation testing.
Playwright provides built-in options to capture test execution details.
Configure HTML Reporter
reporter: [
[‘list’],
[‘html’, {
open: ‘never’
}]
],
Run the tests:
npx playwright test
Open the report:
npx playwright show-report
Configure Screenshots
use: {
screenshot: ‘only-on-failure’
}
This captures screenshots when test cases fail.
Configure Videos
use: {
video: ‘retain-on-failure’
}
This retains recordings for failed tests.
Configure Traces
use: {
trace: ‘retain-on-failure’
}
Trace Viewer helps investigate failed actions, navigation issues, and locator problems.
You can inspect an existing trace using:
npx playwright show-trace test-results/example/trace.zip
These settings are especially useful when tests execute in CI/CD environments without a visible browser window.
9. Run Tests Using Different Configuration Options
After configuring your project, you can control test execution directly from the terminal.
Here are commonly used commands for QA engineers.
| Command | Purpose |
| npx playwright test | Run all tests |
| npx playwright test –headed | Run tests with visible browser |
| npx playwright test –ui | Open interactive UI mode |
| npx playwright test –project=chromium | Run Chromium project only |
| npx playwright test –workers=4 | Run with four workers |
| npx playwright test –retries=2 | Retry failed tests twice |
| npx playwright test tests/login.spec.ts | Run a specific test file |
| npx playwright test –grep “Login | Run tests matching a title |
| npx playwright test –reporter=list | Display list reporter |
| npx playwright test –debug | Debug test execution |
Use Different Configuration Files
You can maintain separate configuration files for different environments.
For example:
playwright.config.ts
playwright.staging.config.ts
playwright.production.config.ts
Execute a specific configuration:
npx playwright test –config=playwright.staging.config.ts
This is useful when the same automated test scripts need to execute against multiple application environments.
Configure a Local Development Server
If your application needs to start before testing, use the webServer option.
webServer: {
command: ‘npm run start’,
url: ‘http://localhost:3000’,
reuseExistingServer: !process.env.CI,
timeout: 120000
}
Playwright waits for the configured URL to become available before starting the tests.
This is useful for applications running locally during development.
10. Complete Playwright TypeScript Config Example
Let’s combine the important settings into one practical configuration file.
Create or update playwright.config.ts:
import { defineConfig, devices } from ‘@playwright/test’;
import dotenv from ‘dotenv’;
dotenv.config();
export default defineConfig({
testDir: ‘./tests’,
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
timeout: 30000,
expect: {
timeout: 5000
},
reporter: [
[‘list’],
[‘html’, { open: ‘never’ }]
],
outputDir: ‘./test-results’,
use: {
baseURL: process.env.BASE_URL || ‘https://example.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’] }
}
]
});
Install dotenv if you have not already:
npm install -D dotenv
Add the following to your .env file:
BASE_URL=https://example.com
This configuration provides browser management, parallel execution, retries, environment-based URLs, screenshots, videos, traces, and HTML reporting.
It is a useful starting point for a professional Playwright TypeScript framework.
11. Integrate Playwright Configuration with Jenkins or GitHub Actions
In real-world QA engineering, automation tests are commonly executed through CI/CD pipelines.
GitHub Actions Integration
Create:
.github/workflows/playwright.yml
name: Playwright Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
– uses: actions/checkout@v6
– uses: actions/setup-node@v6
with:
node-version: lts/*
– name: Install Dependencies
run: npm ci
– name: Install Browsers
run: npx playwright install –with-deps
– name: Run Tests
run: npx playwright test
env:
CI: true
BASE_URL: ${{ vars.BASE_URL }}
– uses: actions/upload-artifact@v5
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
Configure BASE_URL as a GitHub Actions repository variable. Store sensitive credentials separately as GitHub Actions secrets.
Jenkins Integration
You can also execute the configuration through Jenkins.
Create a Jenkinsfile:
pipeline {
agent any
stages {
stage(‘Install Dependencies’) {
steps {
sh ‘npm ci’
}
}
stage(‘Install Browsers’) {
steps {
sh ‘npx playwright install –with-deps’
}
}
stage(‘Execute Tests’) {
steps {
sh ‘npx playwright test’
}
}
}
post {
always {
archiveArtifacts(
artifacts: ‘playwright-report/**’,
allowEmptyArchive: true
)
}
}
}
Make sure the Jenkins agent has Node.js, browser dependencies, and the required permissions.
12. Common Configuration Errors and Troubleshooting
Beginners may encounter configuration errors when developing automation projects.
| Error | Possible Cause | Solution |
| Configuration file not found | Incorrect file location | Place it in the project root |
| Cannot find module | Missing dependency | Run npm install |
| Browser executable missing | Browser binaries not installed | Run npx playwright install |
| Environment variable undefined | Incorrect .env setup | Verify dotenv loading |
| Test timeout exceeded | Slow application or incorrect locator | Investigate the failing action |
| Tests execute twice | Parallel or project configuration misunderstanding | Review project definitions |
| Report not generated | Test execution or reporter configuration issue | Check reporter settings and output directory |
Useful Troubleshooting Commands
npx playwright –version
npx playwright install
npx playwright test –list
npx playwright test –debug
npx playwright show-report
For detailed execution information, use Trace Viewer:
npx playwright show-trace test-results/trace.zip
Trace Viewer helps you inspect browser actions, DOM snapshots, network activity, and errors.
13. Best Practices for Playwright TypeScript Config
Follow these best practices when developing professional automation frameworks.
- Maintain centralized configuration: Avoid repeating browser settings across test files.
- Use environment variables: Manage development, QA, and staging URLs separately.
- Configure appropriate timeouts: Avoid unnecessarily large timeout values.
- Use retries carefully: Investigate flaky tests instead of depending on retries.
- Enable failure artifacts: Capture screenshots, videos, and traces when needed.
- Use browser projects: Validate application behavior across supported browser engines.
- Control parallel workers: Consider application stability and available CI resources.
- Protect authentication data: Never commit storage-state files or credentials to public repositories.
- Maintain clean test data: Keep test data separate from configuration.
- Validate configuration changes: Run a small test suite whenever configuration is modified.
14. Frequently Asked Questions
Q1. What is Playwright TypeScript config?
Playwright TypeScript config is the configuration system used to control automated test execution through playwright.config.ts. It manages browsers, timeouts, retries, reporting, parallel execution, and other test settings.
Q2. What are the benefits of Playwright TypeScript config?
The main benefits include centralized settings, easier browser management, reusable configurations, environment support, automated reporting, and consistent test execution.
Q3. How do I get started with Playwright TypeScript config?
Install Node.js and initialize a project using:
npm init playwright@latest
Select TypeScript during installation and update the generated playwright.config.ts according to your project requirements.
Q4. Can I use multiple configuration files in Playwright?
Yes. You can create separate configuration files for different environments and execute them using the –config command-line option.
Q5. How do I configure retries in Playwright?
Use the following configuration:
retries: process.env.CI ? 2 : 0
This enables two retries in CI environments and no retries during local execution.
Q6. How do I configure multiple browsers?
Use the projects option in playwright.config.ts to define Chromium, Firefox, and WebKit browser configurations.
Q7. Can Playwright configuration support Jenkins?
Yes. Jenkins can execute Playwright tests using npm commands and archive HTML reports and other test artifacts.
