Playwright + TS · Lesson 35 of 36
Module 35: Playwright Configuration
Try it yourself
Implement buildConfigTimeoutSummary:
The editor has a worked example. Read it, tweak it, then press Mark as complete.
playwright.config.ts Templateimport { 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 ? 2 : undefined,
timeout: 30_000, // 30s per test
expect: {
timeout: 5_000, // 5s for retrying assertions
},
reporter: [
["html", { open: "never" }],
["list"],
],
use: {
baseURL: process.env.BASE_URL || "https://staging.targetqa.com",
trace: "retain-on-failure",
screenshot: "only-on-failure",
video: "retain-on-failure",
actionTimeout: 10_000,
navigationTimeout: 15_000,
},
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
{
name: "firefox",
use: { ...devices["Desktop Firefox"] },
},
{
name: "webkit",
use: { ...devices["Desktop Safari"] },
},
],
});Switch environments seamlessly using environment variables:
BASE_URL=https://prod.targetqa.com npx playwright testInside tests, navigate with relative paths:
await page.goto("/dashboard"); // Automatically prepends baseURL!The playwright.config.ts file is the central control hub of your entire automation project. In this masterclass, we will walk through every essential configuration: base URLs, cross-browser projects, viewport sizes, timeouts, retries, reporters, and environment variables. Let's configure our test framework like a pro!
Part of the Playwright + TS course (Playwright with TypeScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
It prevents committing accidental 'test.only()' into version control by crashing the CI build if any .only is detected.
Yes! You can specify 'use: { baseURL: ... }' inside specific project blocks.
Finished reading?
Review the worked example in the editor, then mark the lesson complete.