docs: comparison table for global setups (#35548)
This commit is contained in:
parent
01282e9462
commit
4d0c33bc4e
|
@ -5,7 +5,18 @@ title: "Global setup and teardown"
|
|||
|
||||
## Introduction
|
||||
|
||||
There are two ways to configure global setup and teardown: using a global setup file and setting it in the config under [`globalSetup`](#option-2-configure-globalsetup-and-globalteardown) or using [project dependencies](#option-1-project-dependencies). With project dependencies, you define a project that runs before all other projects. This is the recommended way to configure global setup as with Project dependencies your HTML report will show the global setup, trace viewer will record a trace of the setup and fixtures can be used.
|
||||
There are two ways to configure global setup and teardown: using a global setup file and setting it in the config under [`globalSetup`](#option-2-configure-globalsetup-and-globalteardown) or using [project dependencies](#option-1-project-dependencies). With project dependencies, you define a project that runs before all other projects. This is the recommended approach, as it integrates better with the Playwright test runner: your HTML report will include the global setup, traces will be recorded, and fixtures can be used. For a detailed comparison of the two approaches, see the table below.
|
||||
|
||||
| Feature | Project Dependencies (recommended) | `globalSetup` (config option) |
|
||||
|----------------------------------|-------------------------------------|-----------------------------------|
|
||||
| Runs before all tests | ✅ Yes | ✅ Yes |
|
||||
| HTML report visibility | ✅ Shown as a separate project | ❌ Not shown |
|
||||
| Trace recording | ✅ Full trace available | ❌ Not supported |
|
||||
| Playwright fixtures | ✅ Fully supported | ❌ Not supported |
|
||||
| Browser management | ✅ Via `browser` fixture | ❌ Fully manual via `browserType.launch()` |
|
||||
| Parallelism and retries | ✅ Supported via standard config | ❌ Not applicable |
|
||||
| Config options like `headless` or `testIdAttribute` | ✅ Automatically applied | ❌ Ignored |
|
||||
|
||||
|
||||
## Option 1: Project Dependencies
|
||||
|
||||
|
@ -135,13 +146,7 @@ You can use the `globalSetup` option in the [configuration file](./test-configur
|
|||
Similarly, use `globalTeardown` to run something once after all the tests. Alternatively, let `globalSetup` return a function that will be used as a global teardown. You can pass data such as port number, authentication tokens, etc. from your global setup to your tests using environment variables.
|
||||
|
||||
:::note
|
||||
Beware of `globalSetup` and `globalTeardown` caveats:
|
||||
|
||||
- These methods will not produce traces or artifacts unless explictly enabled, as described in [Capturing trace of failures during global setup](#capturing-trace-of-failures-during-global-setup).
|
||||
- Options such as `headless` or `testIdAttribute` specified in the config file are not applied.
|
||||
- An uncaught exception thrown in `globalSetup` will prevent Playwright from running tests, and no test results will appear in reporters.
|
||||
|
||||
Consider using [project dependencies](#option-1-project-dependencies) to produce traces, artifacts, respect config options and get test results in reporters even in case of a setup failure.
|
||||
Beware that `globalSetup` and `globalTeardown` lack some features — see the [intro](#introduction) section for a detailed comparison. Consider using [project dependencies](#option-1-project-dependencies) instead to get full feature support.
|
||||
:::
|
||||
|
||||
```js title="playwright.config.ts"
|
||||
|
|
Loading…
Reference in New Issue