docs: document passing data from global setup (#7213)

This commit is contained in:
Pavel Feldman 2021-06-17 17:21:22 -07:00 committed by GitHub
parent 4a04a939a9
commit 1b2f0714f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -204,7 +204,7 @@ export const test = base.extend<{ saveLogs: void }>({
To set something up once before running all tests, use `globalSetup` option in the [configuration file](#configuration-object).
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.
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.
Here is a global setup example that runs an app.
```js js-flavor=js
@ -246,6 +246,7 @@ export default globalSetup;
```
Now add `globalSetup` option to the configuration file.
```js js-flavor=js
// playwright.config.js
module.export = {
@ -263,6 +264,26 @@ const config: PlaywrightTestConfig = {
export default config;
```
Tests will now run after the global setup is done and will have access to the data created in the global setup:
```js js-flavor=js
// test.spec.js
const { test } = require('@playwright/test');
test('test', async ({ }) => {
console.log(process.env.SERVER_PORT);
});
```
```js js-flavor=ts
// test.spec.ts
import { test } = from '@playwright/test';
test('test', async ({ }) => {
console.log(process.env.SERVER_PORT);
});
```
## Projects
Playwright Test supports running multiple test projects at the same time. This is useful for running the same tests in multiple configurations. For example, consider running tests against multiple versions of some REST backend.