Configuration and projects
A config has three levels: run behaviour at the top level, context options in use, and run variants in projects. A project is not a folder of tests but a way to run them: a test matched by three projects produces three runs, each with its own use. Command-line flags override the config, and --list shows what will run. CI enables forbidOnly, and flaky in a report means debt.
Playwright · Config and CI
Green locally, red on CI. Is it the test that differs, or the config?
A test is green on a laptop and red on CI. The code is the same but the run is different: locally one project starts, on CI all three browsers; locally there are no retries, on CI there are two, and a test that fails every other run stays unnoticed in a green pipeline. None of this is decided by the test, it is decided by playwright.config.ts. This lesson shows how to split settings into levels, what projects are, and how to check what is going to run.
How it works and why. The config is an ordinary TypeScript module that exports defineConfig(...); the runner reads it once before the run. Settings are split into three levels because they answer three different questions:
| Level | Question | Examples |
|---|---|---|
| Top level | How the run behaves | testDir, timeout, retries, workers, fullyParallel, forbidOnly, reporter, webServer |
use | What the browser context and fixtures are like | baseURL, trace, screenshot, viewport, locale, storageState |
projects[] | Which run variants exist | name, use, testMatch, grep, dependencies, teardown |
A project is not a folder of tests but a run variant. The runner finds all the tests, then for each project runs those that pass its filters (testMatch, grep), with its use. So one test in three projects gives three separate runs, and each one carries the project name in the report. A project's use is layered over the top-level one: whatever the project does not set stays from the shared part. A project can have its own retries, timeout, testDir and fullyParallel.
One file, several runs
Example: the pipeline is green, but a test is unstable. The initial config looks harmless:
// before
export default defineConfig({
retries: 3,
use: { baseURL: 'http://localhost:3000' },
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },
],
});
There are three problems. Retries are the same everywhere: a test that fails every other run is just "re-run" locally and never draws attention. A forgotten test.only will reach the pipeline and quietly shrink the run to one test. And baseURL is hard-coded, so the same suite cannot be run against stage. The fixed version:
// after
export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI, // test.only on CI = an error
retries: process.env.CI ? 2 : 0, // locally a failure is visible at once
reporter: process.env.CI ? [['blob'], ['github']] : [['html', { open: 'never' }]],
use: {
baseURL: process.env.BASE_URL ?? 'http://localhost:3000',
trace: 'on-first-retry', // a trace only when there was a second attempt
screenshot: 'only-on-failure',
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },
{ name: 'mobile', use: { ...devices['Pixel 7'] }, grep: /@mobile/ },
],
});
A test that passed on the second attempt has the status flaky in the report, not passed, and trace: 'on-first-retry' keeps a trace for it. That is why retries on CI are acceptable: they do not hide the problem as long as someone looks at the report. You can check what will run without running the tests:
npx playwright test --list
Listing tests:
[chromium] › checkout.spec.ts:4:5 › pay by card
[firefox] › checkout.spec.ts:4:5 › pay by card
[chromium] › checkout.spec.ts:12:5 › mobile menu
[firefox] › checkout.spec.ts:12:5 › mobile menu
[mobile] › checkout.spec.ts:12:5 › mobile menu
Total: 5 tests in 1 file
Each line shows the project in square brackets, so it is clear at once what will go to CI. A single project is run with --project=chromium; the flag can be repeated.
Skipping a test: how it looks in the report
if inside the body
The test does a return on the mobile project. In the report it is "passed" without a single check, and nobody knows that nothing was executed.
test.skip with a condition
test.skip(isMobile, 'reason'): the report shows "skipped" and the reason text, so it is visible what was not verified.
test('drag and drop cards', async ({ page, browserName, isMobile }) => {
test.skip(isMobile, 'Drag and drop is not supported in the mobile version');
test.fixme(browserName === 'webkit', 'Known WebKit bug, see the ticket');
// …
});
Limits and alternatives. Command-line flags take priority over the config: --retries, --workers, --project, --grep and --reporter override the values from the file, so on CI they can be changed without editing code. If there are several configs (a regular one and one for a nightly run), the shared part goes into a base object: defineConfig(base, { … }) merges them. Without an explicit reporter Playwright uses dot on CI and list locally, so without your own reporter CI has no HTML report. Cypress has a similar role in the e2e block of cypress.config.ts and the --browser flag, but there are no "projects" as separate run variants. Selenium has no runner with a config: you assemble the browser matrix yourself, through TestNG, pytest or CI.
Common mistakes.
- Putting
baseURLorstorageStateat the top level: these are context options, they belong inuse. TypeScript will flag the extra key, while in a JS config it is simply ignored, andpage.goto('/')fails because the relative path has no base. - Making a project for every small thing: copies of nearly identical projects drift apart. The shared part goes into an object extended through
.... - A
mobileproject withoutgreportestMatch: the whole suite also runs in the mobile profile, the run takes twice as long, and half of the failures are noise. - High
retrieslocally: unstable tests become invisible and are discovered when there are already many. - No
forbidOnlyon CI: one forgottentest.onlyremoves all other tests from the run.
Check yourself
The config has chromium, firefox and mobile (with grep: /@mobile/). A file has two tests, one tagged @mobile. How many runs will the report show?
Answer
Five: 2 in chromium, 2 in firefox and 1 in mobile. Projects without grep take all tests, while mobile takes only those that pass the filter.
A test passed on CI on the second attempt, the pipeline is green. Does that mean everything is fine?
Answer
No. The report status will be flaky: the test is unstable, the retry only kept it from stopping the run. Open the trace (with on-first-retry it is recorded on the retry; a trace of the failure itself needs retain-on-first-failure) and find the cause, instead of treating a green pipeline as proof of stability.
baseURL is written at the top level of the config, and page.goto('/login') does not work. What is wrong?
Answer
baseURL is a context option, so it lives in use. There is no such key at the top level: TypeScript shows this, while a JS config silently ignores the key and the relative path is left without a base.
use and projects: each project, for example a browser, runs the tests with its own options. Middle/Senior: I treat a project as a run variant: a test in three projects gives three runs in the report. On CI I turn on forbidOnly, retries and trace: 'on-first-retry', but I remember that flaky in the report means debt, not success. I make conditional skips through test.skip with a reason so they stay visible, and before a pipeline I check the make-up of the run with --list.