Playwright has a configuration file, typically named playwright.config.ts
, where we can specify various options to configure how our tests are run.
We've configured Playwright for multiple environments using the dotenv package. The isCI
constant here, indicates whether the test is running in a Continuous Integration (CI) environment.
Following is the configuration we have used.
Let's checkout some notable terms in the configuration above.
STORAGE_STATE: This constant variable points to the file path where user session related cookies are stored.
testDir: Specifies the directory where the test files are located.
timeout: Sets the maximum time a test can run. A value of 0 removes any upper time limit.
fullyParallel: If true, all tests in all files run in parallel.
forbidOnly: If true, CI build fails if test.only
is accidentally left in the source code.
retries: Maximum number of retry attempts per test.
workers: Maximum number of concurrent worker processes for parallelizing tests.
reporter: Controls how test results are displayed or saved.
use: Specifies test options shared across all projects.
baseURL: Sets the base URL used in actions like await page.goto('/').
testIdAttribute: Custom attribute used in page.getByTestId()
.
trace: Records trace for each test (defaults to off).
video: Records video for each test (defaults to off).
screenshot: Automatically captures a screenshot after each test (defaults to off).
The projects configuration includes three projects:
-
Setup: Performs a global setup before all projects are run. We have configured the login functionality of the application in this setup.
-
Chromium: Actual tests are run in this project. The setup project is a dependency, ensuring it runs before the Chromium project tests.
-
Cleanup Credentials: Performs a global teardown after all projects are run. We have configured the clearing of user session details in this project.
This configuration ensures a systematic execution order, with setup tests running before actual tests and cleanup occurring after all projects finish.
There is nothing to commit in this chapter. If you have made some changes to the project, clean them up by executing the following command.