diff --git a/docs/src/test-api/class-fixtures.md b/docs/src/test-api/class-fixtures.md index adec232fb0..f476a08ada 100644 --- a/docs/src/test-api/class-fixtures.md +++ b/docs/src/test-api/class-fixtures.md @@ -23,158 +23,42 @@ test('basic test', async ({ page }) => { Given the test above, Playwright Test will set up the `page` fixture before running the test, and tear it down after the test has finished. `page` fixture provides a [Page] object that is available to the test. -Playwright Test comes with builtin fixtures listed below, and you can add your own fixtures as well. Many fixtures are designed as "options" that you can set in your [`property: TestConfig.use`] section. +Playwright Test comes with builtin fixtures listed below, and you can add your own fixtures as well. Playwright Test also [provides options][TestOptions] to configure [`property: Fixtures.browser`], [`property: Fixtures.context`] and [`property: Fixtures.page`]. -```js js-flavor=js -// @ts-check +## property: Fixtures.browser +- type: <[Browser]> -/** @type {import('@playwright/test').PlaywrightTestConfig} */ -const config = { - use: { - headless: false, - viewport: { width: 1280, height: 720 }, - ignoreHTTPSErrors: true, - video: 'on-first-retry', - }, -}; +[Browser] instance is shared between all tests in the [same worker](./test-parallel.md) - this makes testing efficient. However, each test runs in an isolated [BrowserContext] and gets a fresh environment. -module.exports = config; -``` - -```js js-flavor=ts -import { PlaywrightTestConfig } from '@playwright/test'; -const config: PlaywrightTestConfig = { - use: { - headless: false, - viewport: { width: 1280, height: 720 }, - ignoreHTTPSErrors: true, - video: 'on-first-retry', - }, -}; -export default config; -``` - -Alternatively, with [`method: Test.use`] you can override some options for a file. - -```js js-flavor=js -// example.spec.js -const { test, expect } = require('@playwright/test'); - -// Run tests in this file with portrait-like viewport. -test.use({ viewport: { width: 600, height: 900 } }); - -test('my portrait test', async ({ page }) => { - // ... -}); -``` - -```js js-flavor=ts -// example.spec.ts -import { test, expect } from '@playwright/test'; - -// Run tests in this file with portrait-like viewport. -test.use({ viewport: { width: 600, height: 900 } }); - -test('my portrait test', async ({ page }) => { - // ... -}); -``` - -## property: Fixtures.acceptDownloads = %%-context-option-acceptdownloads-%% - -## property: Fixtures.baseURL = %%-context-option-baseURL-%% +Learn how to [configure browser](./test-configuration.md) and see [available options][TestOptions]. ## property: Fixtures.browserName - type: <[BrowserName]<"chromium"|"firefox"|"webkit">> -Name of the browser that runs tests. Defaults to `'chromium'`. Most of the time you should set `browserName` in your [TestConfig]: +Name of the browser that runs tests. Defaults to `'chromium'`. Useful to [annotate tests](./test-annotations.md) based on the browser. ```js js-flavor=js -// playwright.config.js -// @ts-check - -/** @type {import('@playwright/test').PlaywrightTestConfig} */ -const config = { - use: { - browserName: 'firefox', - }, -}; - -module.exports = config; +test('skip this test in Firefox', async ({ page, browserName }) => { + test.skip(browserName === 'firefox', 'Still working on it'); + // ... +}); ``` ```js js-flavor=ts -// playwright.config.ts -import { PlaywrightTestConfig, devices } from '@playwright/test'; - -const config: PlaywrightTestConfig = { - use: { - browserName: 'firefox', - }, -}; -export default config; +test('skip this test in Firefox', async ({ page, browserName }) => { + test.skip(browserName === 'firefox', 'Still working on it'); + // ... +}); ``` -## property: Fixtures.actionTimeout -- type: <[int]> - -Default timeout for each Playwright action in milliseconds, defaults to 0 (no timeout). - -This is a default timeout for all Playwright actions, same as configured via [`method: Page.setDefaultTimeout`]. - -## property: Fixtures.bypassCSP = %%-context-option-bypasscsp-%% - -## property: Fixtures.channel = %%-browser-option-channel-%% - -## property: Fixtures.colorScheme = %%-context-option-colorscheme-%% - ## property: Fixtures.context - type: <[BrowserContext]> Isolated [BrowserContext] instance, created for each test. Since contexts are isolated between each other, every test gets a fresh environment, even when multiple tests run in a single [Browser] for maximum efficiency. -Learn how to [configure context](./test-configuration.md) through other fixtures and options. +Learn how to [configure context](./test-configuration.md) and see [available options][TestOptions]. -The [`property: Fixtures.page`] belongs to this context. - -## property: Fixtures.contextOptions -- type: <[Object]> - -Options used to create the context, as passed to [`method: Browser.newContext`]. Specific options like [`property: Fixtures.viewport`] take priority over this. - -## property: Fixtures.deviceScaleFactor = %%-context-option-devicescalefactor-%% - -## property: Fixtures.extraHTTPHeaders = %%-context-option-extrahttpheaders-%% - -## property: Fixtures.geolocation = %%-context-option-geolocation-%% - -## property: Fixtures.hasTouch = %%-context-option-hastouch-%% - -## property: Fixtures.headless = %%-browser-option-headless-%% - -## property: Fixtures.httpCredentials = %%-context-option-httpcredentials-%% - -## property: Fixtures.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%% - -## property: Fixtures.isMobile = %%-context-option-ismobile-%% - -## property: Fixtures.javaScriptEnabled = %%-context-option-javascriptenabled-%% - -## property: Fixtures.launchOptions -- type: <[Object]> - -Options used to launch the browser, as passed to [`method: BrowserType.launch`]. Specific options [`property: Fixtures.headless`] and [`property: Fixtures.channel`] take priority over this. - -## property: Fixtures.locale = %%-context-option-locale-%% - -## property: Fixtures.navigationTimeout -- type: <[int]> - -Timeout for each navigation action in milliseconds. Defaults to 0 (no timeout). - -This is a default navigation timeout, same as configured via [`method: Page.setDefaultNavigationTimeout`]. - -## property: Fixtures.offline = %%-context-option-offline-%% +Default [`property: Fixtures.page`] belongs to this context. ## property: Fixtures.page - type: <[Page]> @@ -206,52 +90,3 @@ test('basic test', async ({ page }) => { // ... }); ``` - -## property: Fixtures.permissions = %%-context-option-permissions-%% - -## property: Fixtures.proxy = %%-browser-option-proxy-%% - -## property: Fixtures.screenshot -- type: <[Screenshot]<"off"|"on"|"only-on-failure">> - -Whether to automatically capture a screenshot after each test. Defaults to `'off'`. -* `'off'`: Do not capture screenshots. -* `'on'`: Capture screenshot after each test. -* `'only-on-failure'`: Capture screenshot after each test failure. - -Learn more about [automatic screenshots](./test-configuration.md#automatic-screenshots). - -## property: Fixtures.storageState = %%-js-python-context-option-storage-state-%% - -## property: Fixtures.timezoneId = %%-context-option-timezoneid-%% - -## property: Fixtures.trace -- type: <[Screenshot]<"off"|"on"|"retain-on-failure"|"on-first-retry">> - -Whether to record a trace for each test. Defaults to `'off'`. -* `'off'`: Do not record a trace. -* `'on'`: Record a trace for each test. -* `'retain-on-failure'`: Record a trace for each test, but remove it from successful test runs. -* `'on-first-retry'`: Record a trace only when retrying a test for the first time. - -Learn more about [recording trace](./test-configuration.md#record-test-trace). - -## property: Fixtures.userAgent = %%-context-option-useragent-%% - -## property: Fixtures.video -- type: <[Object]|[VideoMode]<"off"|"on"|"retain-on-failure"|"on-first-retry">> - - `mode` <[VideoMode]<"off"|"on"|"retain-on-failure"|"on-first-retry">> Video recording mode. - - `size` <[Object]> Size of the recorded video. - - `width` <[int]> - - `height` <[int]> - -Whether to record video for each test. Defaults to `'off'`. -* `'off'`: Do not record video. -* `'on'`: Record video for each test. -* `'retain-on-failure'`: Record video for each test, but remove all videos from successful test runs. -* `'on-first-retry'`: Record video only when retrying a test for the first time. - -Learn more about [recording video](./test-configuration.md#record-video). - -## property: Fixtures.viewport = %%-context-option-viewport-%% - diff --git a/docs/src/test-api/class-test.md b/docs/src/test-api/class-test.md index 5113ce3ebc..cef099836e 100644 --- a/docs/src/test-api/class-test.md +++ b/docs/src/test-api/class-test.md @@ -974,7 +974,7 @@ Step body. ## method: Test.use -Specifies parameters or fixtures to use in a single test file or a [`method: Test.describe`] group. Most useful to configure a fixture, for example set `locale` to configure `context` fixture. +Specifies options or fixtures to use in a single test file or a [`method: Test.describe`] group. Most useful to set an option, for example set `locale` to configure `context` fixture. ```js js-flavor=js const { test, expect } = require('@playwright/test'); @@ -996,7 +996,7 @@ test('test with locale', async ({ page }) => { }); ``` -It is possible not only to provide a fixture value, but also to override a fixture by providing a fixture function. +It is also possible to override a fixture by providing a function. ```js js-flavor=js const { test, expect } = require('@playwright/test'); @@ -1031,8 +1031,8 @@ test('test with locale', async ({ page }) => { ``` ### param: Test.use.fixtures -- `fixtures` <[Fixtures]> +- `options` <[TestOptions]> -An object with fixture definitions. +An object with local options. diff --git a/docs/src/test-api/class-testconfig.md b/docs/src/test-api/class-testconfig.md index 27bef1ceee..a86723131e 100644 --- a/docs/src/test-api/class-testconfig.md +++ b/docs/src/test-api/class-testconfig.md @@ -267,9 +267,9 @@ Whether to update expected snapshots with the actual results produced by the tes Learn more about [snapshots](./test-snapshots.md). ## property: TestConfig.use -- type: <[Fixtures]> +- type: <[TestOptions]> -Additional fixtures for this project. Most useful for specifying options, for example [`property: Fixtures.browserName`]. Learn more about [Fixtures] and [configuration](./test-configuration.md). +Global options for all tests, for example [`property: TestOptions.browserName`]. Learn more about [configuration](./test-configuration.md) and see [available options][TestOptions]. ```js js-flavor=js // playwright.config.js diff --git a/docs/src/test-api/class-testoptions.md b/docs/src/test-api/class-testoptions.md new file mode 100644 index 0000000000..76f150a7c3 --- /dev/null +++ b/docs/src/test-api/class-testoptions.md @@ -0,0 +1,197 @@ +# class: TestOptions +* langs: js + +Playwright Test provides many options to configure test environment, [Browser], [BrowserContext] and more. + +These options are usually provided in the [configuration file](./test-configuration.md) through [`property: TestConfig.use`] and [`property: TestProject.use`]. + +```js js-flavor=js +// @ts-check + +/** @type {import('@playwright/test').PlaywrightTestConfig} */ +const config = { + use: { + headless: false, + viewport: { width: 1280, height: 720 }, + ignoreHTTPSErrors: true, + video: 'on-first-retry', + }, +}; + +module.exports = config; +``` + +```js js-flavor=ts +import { PlaywrightTestConfig } from '@playwright/test'; +const config: PlaywrightTestConfig = { + use: { + headless: false, + viewport: { width: 1280, height: 720 }, + ignoreHTTPSErrors: true, + video: 'on-first-retry', + }, +}; +export default config; +``` + +Alternatively, with [`method: Test.use`] you can override some options for a file. + +```js js-flavor=js +// example.spec.js +const { test, expect } = require('@playwright/test'); + +// Run tests in this file with portrait-like viewport. +test.use({ viewport: { width: 600, height: 900 } }); + +test('my portrait test', async ({ page }) => { + // ... +}); +``` + +```js js-flavor=ts +// example.spec.ts +import { test, expect } from '@playwright/test'; + +// Run tests in this file with portrait-like viewport. +test.use({ viewport: { width: 600, height: 900 } }); + +test('my portrait test', async ({ page }) => { + // ... +}); +``` + +## property: TestOptions.acceptDownloads = %%-context-option-acceptdownloads-%% + +## property: TestOptions.baseURL = %%-context-option-baseURL-%% + +## property: TestOptions.browserName +- type: <[BrowserName]<"chromium"|"firefox"|"webkit">> + +Name of the browser that runs tests. Defaults to `'chromium'`. Most of the time you should set `browserName` in your [TestConfig]: + +```js js-flavor=js +// playwright.config.js +// @ts-check + +/** @type {import('@playwright/test').PlaywrightTestConfig} */ +const config = { + use: { + browserName: 'firefox', + }, +}; + +module.exports = config; +``` + +```js js-flavor=ts +// playwright.config.ts +import { PlaywrightTestConfig, devices } from '@playwright/test'; + +const config: PlaywrightTestConfig = { + use: { + browserName: 'firefox', + }, +}; +export default config; +``` + +## property: TestOptions.actionTimeout +- type: <[int]> + +Default timeout for each Playwright action in milliseconds, defaults to 0 (no timeout). + +This is a default timeout for all Playwright actions, same as configured via [`method: Page.setDefaultTimeout`]. + +## property: TestOptions.bypassCSP = %%-context-option-bypasscsp-%% + +## property: TestOptions.channel = %%-browser-option-channel-%% + +## property: TestOptions.colorScheme = %%-context-option-colorscheme-%% + +## property: TestOptions.contextOptions +- type: <[Object]> + +Options used to create the context, as passed to [`method: Browser.newContext`]. Specific options like [`property: TestOptions.viewport`] take priority over this. + +## property: TestOptions.deviceScaleFactor = %%-context-option-devicescalefactor-%% + +## property: TestOptions.extraHTTPHeaders = %%-context-option-extrahttpheaders-%% + +## property: TestOptions.geolocation = %%-context-option-geolocation-%% + +## property: TestOptions.hasTouch = %%-context-option-hastouch-%% + +## property: TestOptions.headless = %%-browser-option-headless-%% + +## property: TestOptions.httpCredentials = %%-context-option-httpcredentials-%% + +## property: TestOptions.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%% + +## property: TestOptions.isMobile = %%-context-option-ismobile-%% + +## property: TestOptions.javaScriptEnabled = %%-context-option-javascriptenabled-%% + +## property: TestOptions.launchOptions +- type: <[Object]> + +Options used to launch the browser, as passed to [`method: BrowserType.launch`]. Specific options [`property: TestOptions.headless`] and [`property: TestOptions.channel`] take priority over this. + +## property: TestOptions.locale = %%-context-option-locale-%% + +## property: TestOptions.navigationTimeout +- type: <[int]> + +Timeout for each navigation action in milliseconds. Defaults to 0 (no timeout). + +This is a default navigation timeout, same as configured via [`method: Page.setDefaultNavigationTimeout`]. + +## property: TestOptions.offline = %%-context-option-offline-%% + +## property: TestOptions.permissions = %%-context-option-permissions-%% + +## property: TestOptions.proxy = %%-browser-option-proxy-%% + +## property: TestOptions.screenshot +- type: <[Screenshot]<"off"|"on"|"only-on-failure">> + +Whether to automatically capture a screenshot after each test. Defaults to `'off'`. +* `'off'`: Do not capture screenshots. +* `'on'`: Capture screenshot after each test. +* `'only-on-failure'`: Capture screenshot after each test failure. + +Learn more about [automatic screenshots](./test-configuration.md#automatic-screenshots). + +## property: TestOptions.storageState = %%-js-python-context-option-storage-state-%% + +## property: TestOptions.timezoneId = %%-context-option-timezoneid-%% + +## property: TestOptions.trace +- type: <[Screenshot]<"off"|"on"|"retain-on-failure"|"on-first-retry">> + +Whether to record a trace for each test. Defaults to `'off'`. +* `'off'`: Do not record a trace. +* `'on'`: Record a trace for each test. +* `'retain-on-failure'`: Record a trace for each test, but remove it from successful test runs. +* `'on-first-retry'`: Record a trace only when retrying a test for the first time. + +Learn more about [recording trace](./test-configuration.md#record-test-trace). + +## property: TestOptions.userAgent = %%-context-option-useragent-%% + +## property: TestOptions.video +- type: <[Object]|[VideoMode]<"off"|"on"|"retain-on-failure"|"on-first-retry">> + - `mode` <[VideoMode]<"off"|"on"|"retain-on-failure"|"on-first-retry">> Video recording mode. + - `size` <[Object]> Size of the recorded video. + - `width` <[int]> + - `height` <[int]> + +Whether to record video for each test. Defaults to `'off'`. +* `'off'`: Do not record video. +* `'on'`: Record video for each test. +* `'retain-on-failure'`: Record video for each test, but remove all videos from successful test runs. +* `'on-first-retry'`: Record video only when retrying a test for the first time. + +Learn more about [recording video](./test-configuration.md#record-video). + +## property: TestOptions.viewport = %%-context-option-viewport-%% + diff --git a/docs/src/test-api/class-testproject.md b/docs/src/test-api/class-testproject.md index a6feb19d4a..c5feeeaebd 100644 --- a/docs/src/test-api/class-testproject.md +++ b/docs/src/test-api/class-testproject.md @@ -277,7 +277,7 @@ This is a base timeout for all tests. In addition, each test can configure its o ## property: TestProject.use - type: <[Fixtures]> -Additional fixtures for this project. Most useful for specifying options, for example [`property: Fixtures.browserName`]. Learn more about [Fixtures] and [configuration](./test-configuration.md). +Options for all tests in this project, for example [`property: TestOptions.browserName`]. Learn more about [configuration](./test-configuration.md) and see [available options][TestOptions]. ```js js-flavor=js // playwright.config.js diff --git a/docs/src/test-configuration-js.md b/docs/src/test-configuration-js.md index a800786704..a306da455c 100644 --- a/docs/src/test-configuration-js.md +++ b/docs/src/test-configuration-js.md @@ -9,11 +9,13 @@ Finally, there are plenty of testing options like `timeout` or `testDir` that co You can specify any options globally in the configuration file, and most of them locally in a test file. +See the full list of [test options][TestOptions] and all [configuration properties][TestConfig]. + ## Global configuration -Create `playwright.config.js` (or `playwright.config.ts`) and specify options in the `use` section. +Create `playwright.config.js` (or `playwright.config.ts`) and specify options in the [`property: TestConfig.use`] section. ```js js-flavor=js // @ts-check @@ -58,7 +60,7 @@ npx playwright test --config=tests/my.config.js ## Local configuration -With `test.use()` you can override some options for a file or a `test.describe` block. +With [`method: Test.use`] you can override some options for a file or a [`method: Test.describe`] block. ```js js-flavor=js // example.spec.js diff --git a/types/test.d.ts b/types/test.d.ts index 7ffe5c89d1..5f3dcd2bee 100644 --- a/types/test.d.ts +++ b/types/test.d.ts @@ -284,9 +284,9 @@ interface TestProject { export interface Project extends TestProject { define?: FixtureDefine | FixtureDefine[]; /** - * Additional fixtures for this project. Most useful for specifying options, for example - * [fixtures.browserName](https://playwright.dev/docs/api/class-fixtures#fixtures-browser-name). Learn more about - * [Fixtures] and [configuration](https://playwright.dev/docs/test-configuration). + * Options for all tests in this project, for example + * [testOptions.browserName](https://playwright.dev/docs/api/class-testoptions#test-options-browser-name). Learn more about + * [configuration](https://playwright.dev/docs/test-configuration) and see [available options][TestOptions]. * * ```ts * // playwright.config.ts @@ -595,9 +595,9 @@ export interface Config extends TestConfig { projects?: Project[]; define?: FixtureDefine | FixtureDefine[]; /** - * Additional fixtures for this project. Most useful for specifying options, for example - * [fixtures.browserName](https://playwright.dev/docs/api/class-fixtures#fixtures-browser-name). Learn more about - * [Fixtures] and [configuration](https://playwright.dev/docs/test-configuration). + * Global options for all tests, for example + * [testOptions.browserName](https://playwright.dev/docs/api/class-testoptions#test-options-browser-name). Learn more about + * [configuration](https://playwright.dev/docs/test-configuration) and see [available options][TestOptions]. * * ```ts * // playwright.config.ts @@ -2218,9 +2218,9 @@ export interface TestType Promise | any): void; /** - * Specifies parameters or fixtures to use in a single test file or a - * [test.describe(title, callback)](https://playwright.dev/docs/api/class-test#test-describe) group. Most useful to - * configure a fixture, for example set `locale` to configure `context` fixture. + * Specifies options or fixtures to use in a single test file or a + * [test.describe(title, callback)](https://playwright.dev/docs/api/class-test#test-describe) group. Most useful to set an + * option, for example set `locale` to configure `context` fixture. * * ```ts * import { test, expect } from '@playwright/test'; @@ -2232,7 +2232,7 @@ export interface TestType): void; /** @@ -2302,27 +2302,11 @@ type Proxy = Exclude; type StorageState = Exclude; /** - * Playwright Test is based on the concept of the [test fixtures](https://playwright.dev/docs/test-fixtures). Test fixtures are used to establish - * environment for each test, giving the test everything it needs and nothing else. + * Playwright Test provides many options to configure test environment, [Browser], [BrowserContext] and more. * - * Playwright Test looks at each test declaration, analyses the set of fixtures the test needs and prepares those fixtures - * specifically for the test. Values prepared by the fixtures are merged into a single object that is available to the - * `test`, hooks, annotations and other fixtures as a first parameter. - * - * ```ts - * import { test, expect } from '@playwright/test'; - * - * test('basic test', async ({ page }) => { - * // ... - * }); - * ``` - * - * Given the test above, Playwright Test will set up the `page` fixture before running the test, and tear it down after the - * test has finished. `page` fixture provides a [Page] object that is available to the test. - * - * Playwright Test comes with builtin fixtures listed below, and you can add your own fixtures as well. Many fixtures are - * designed as "options" that you can set in your - * [testConfig.use](https://playwright.dev/docs/api/class-testconfig#test-config-use) section. + * These options are usually provided in the [configuration file](https://playwright.dev/docs/test-configuration) through + * [testConfig.use](https://playwright.dev/docs/api/class-testconfig#test-config-use) and + * [testProject.use](https://playwright.dev/docs/api/class-testproject#test-project-use). * * ```ts * import { PlaywrightTestConfig } from '@playwright/test'; @@ -2337,7 +2321,7 @@ type StorageState = Exclude; * export default config; * ``` * - * Alternatively, with [test.use(fixtures)](https://playwright.dev/docs/api/class-test#test-use) you can override some + * Alternatively, with [test.use(options)](https://playwright.dev/docs/api/class-test#test-use) you can override some * options for a file. * * ```ts @@ -2389,8 +2373,8 @@ export interface PlaywrightWorkerOptions { /** * Options used to launch the browser, as passed to * [browserType.launch([options])](https://playwright.dev/docs/api/class-browsertype#browser-type-launch). Specific options - * [fixtures.headless](https://playwright.dev/docs/api/class-fixtures#fixtures-headless) and - * [fixtures.channel](https://playwright.dev/docs/api/class-fixtures#fixtures-channel) take priority over this. + * [testOptions.headless](https://playwright.dev/docs/api/class-testoptions#test-options-headless) and + * [testOptions.channel](https://playwright.dev/docs/api/class-testoptions#test-options-channel) take priority over this. */ launchOptions: LaunchOptions; /** @@ -2427,27 +2411,11 @@ export interface PlaywrightWorkerOptions { export type VideoMode = 'off' | 'on' | 'retain-on-failure' | 'on-first-retry' | /** deprecated */ 'retry-with-video'; /** - * Playwright Test is based on the concept of the [test fixtures](https://playwright.dev/docs/test-fixtures). Test fixtures are used to establish - * environment for each test, giving the test everything it needs and nothing else. + * Playwright Test provides many options to configure test environment, [Browser], [BrowserContext] and more. * - * Playwright Test looks at each test declaration, analyses the set of fixtures the test needs and prepares those fixtures - * specifically for the test. Values prepared by the fixtures are merged into a single object that is available to the - * `test`, hooks, annotations and other fixtures as a first parameter. - * - * ```ts - * import { test, expect } from '@playwright/test'; - * - * test('basic test', async ({ page }) => { - * // ... - * }); - * ``` - * - * Given the test above, Playwright Test will set up the `page` fixture before running the test, and tear it down after the - * test has finished. `page` fixture provides a [Page] object that is available to the test. - * - * Playwright Test comes with builtin fixtures listed below, and you can add your own fixtures as well. Many fixtures are - * designed as "options" that you can set in your - * [testConfig.use](https://playwright.dev/docs/api/class-testconfig#test-config-use) section. + * These options are usually provided in the [configuration file](https://playwright.dev/docs/test-configuration) through + * [testConfig.use](https://playwright.dev/docs/api/class-testconfig#test-config-use) and + * [testProject.use](https://playwright.dev/docs/api/class-testproject#test-project-use). * * ```ts * import { PlaywrightTestConfig } from '@playwright/test'; @@ -2462,7 +2430,7 @@ export type VideoMode = 'off' | 'on' | 'retain-on-failure' | 'on-first-retry' | * export default config; * ``` * - * Alternatively, with [test.use(fixtures)](https://playwright.dev/docs/api/class-test#test-use) you can override some + * Alternatively, with [test.use(options)](https://playwright.dev/docs/api/class-test#test-use) you can override some * options for a file. * * ```ts @@ -2578,7 +2546,8 @@ export interface PlaywrightTestOptions { /** * Options used to create the context, as passed to * [browser.newContext([options])](https://playwright.dev/docs/api/class-browser#browser-new-context). Specific options - * like [fixtures.viewport](https://playwright.dev/docs/api/class-fixtures#fixtures-viewport) take priority over this. + * like [testOptions.viewport](https://playwright.dev/docs/api/class-testoptions#test-options-viewport) take priority over + * this. */ contextOptions: BrowserContextOptions; /** @@ -2617,41 +2586,20 @@ export interface PlaywrightTestOptions { * Given the test above, Playwright Test will set up the `page` fixture before running the test, and tear it down after the * test has finished. `page` fixture provides a [Page] object that is available to the test. * - * Playwright Test comes with builtin fixtures listed below, and you can add your own fixtures as well. Many fixtures are - * designed as "options" that you can set in your - * [testConfig.use](https://playwright.dev/docs/api/class-testconfig#test-config-use) section. - * - * ```ts - * import { PlaywrightTestConfig } from '@playwright/test'; - * const config: PlaywrightTestConfig = { - * use: { - * headless: false, - * viewport: { width: 1280, height: 720 }, - * ignoreHTTPSErrors: true, - * video: 'on-first-retry', - * }, - * }; - * export default config; - * ``` - * - * Alternatively, with [test.use(fixtures)](https://playwright.dev/docs/api/class-test#test-use) you can override some - * options for a file. - * - * ```ts - * // example.spec.ts - * import { test, expect } from '@playwright/test'; - * - * // Run tests in this file with portrait-like viewport. - * test.use({ viewport: { width: 600, height: 900 } }); - * - * test('my portrait test', async ({ page }) => { - * // ... - * }); - * ``` - * + * Playwright Test comes with builtin fixtures listed below, and you can add your own fixtures as well. Playwright Test + * also [provides options][TestOptions] to configure + * [fixtures.browser](https://playwright.dev/docs/api/class-fixtures#fixtures-browser), + * [fixtures.context](https://playwright.dev/docs/api/class-fixtures#fixtures-context) and + * [fixtures.page](https://playwright.dev/docs/api/class-fixtures#fixtures-page). */ export interface PlaywrightWorkerArgs { playwright: typeof import('..'); + /** + * [Browser] instance is shared between all tests in the [same worker](https://playwright.dev/docs/test-parallel) - this makes testing efficient. + * However, each test runs in an isolated [BrowserContext] and gets a fresh environment. + * + * Learn how to [configure browser](https://playwright.dev/docs/test-configuration) and see [available options][TestOptions]. + */ browser: Browser; } @@ -2674,48 +2622,20 @@ export interface PlaywrightWorkerArgs { * Given the test above, Playwright Test will set up the `page` fixture before running the test, and tear it down after the * test has finished. `page` fixture provides a [Page] object that is available to the test. * - * Playwright Test comes with builtin fixtures listed below, and you can add your own fixtures as well. Many fixtures are - * designed as "options" that you can set in your - * [testConfig.use](https://playwright.dev/docs/api/class-testconfig#test-config-use) section. - * - * ```ts - * import { PlaywrightTestConfig } from '@playwright/test'; - * const config: PlaywrightTestConfig = { - * use: { - * headless: false, - * viewport: { width: 1280, height: 720 }, - * ignoreHTTPSErrors: true, - * video: 'on-first-retry', - * }, - * }; - * export default config; - * ``` - * - * Alternatively, with [test.use(fixtures)](https://playwright.dev/docs/api/class-test#test-use) you can override some - * options for a file. - * - * ```ts - * // example.spec.ts - * import { test, expect } from '@playwright/test'; - * - * // Run tests in this file with portrait-like viewport. - * test.use({ viewport: { width: 600, height: 900 } }); - * - * test('my portrait test', async ({ page }) => { - * // ... - * }); - * ``` - * + * Playwright Test comes with builtin fixtures listed below, and you can add your own fixtures as well. Playwright Test + * also [provides options][TestOptions] to configure + * [fixtures.browser](https://playwright.dev/docs/api/class-fixtures#fixtures-browser), + * [fixtures.context](https://playwright.dev/docs/api/class-fixtures#fixtures-context) and + * [fixtures.page](https://playwright.dev/docs/api/class-fixtures#fixtures-page). */ export interface PlaywrightTestArgs { - createContext: (options?: BrowserContextOptions) => Promise; /** * Isolated [BrowserContext] instance, created for each test. Since contexts are isolated between each other, every test * gets a fresh environment, even when multiple tests run in a single [Browser] for maximum efficiency. * - * Learn how to [configure context](https://playwright.dev/docs/test-configuration) through other fixtures and options. + * Learn how to [configure context](https://playwright.dev/docs/test-configuration) and see [available options][TestOptions]. * - * The [fixtures.page](https://playwright.dev/docs/api/class-fixtures#fixtures-page) belongs to this context. + * Default [fixtures.page](https://playwright.dev/docs/api/class-fixtures#fixtures-page) belongs to this context. */ context: BrowserContext; /** diff --git a/utils/generate_types/index.js b/utils/generate_types/index.js index e586dd21d0..f6ba643efd 100644 --- a/utils/generate_types/index.js +++ b/utils/generate_types/index.js @@ -494,8 +494,8 @@ class TypesGenerator { ['Config', 'TestConfig'], ['FullConfig', 'TestConfig'], ['Project', 'TestProject'], - ['PlaywrightWorkerOptions', 'Fixtures'], - ['PlaywrightTestOptions', 'Fixtures'], + ['PlaywrightWorkerOptions', 'TestOptions'], + ['PlaywrightTestOptions', 'TestOptions'], ['PlaywrightWorkerArgs', 'Fixtures'], ['PlaywrightTestArgs', 'Fixtures'], ]); diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts index 815d39e9ce..0dc3004bd1 100644 --- a/utils/generate_types/overrides-test.d.ts +++ b/utils/generate_types/overrides-test.d.ts @@ -330,7 +330,6 @@ export interface PlaywrightWorkerArgs { } export interface PlaywrightTestArgs { - createContext: (options?: BrowserContextOptions) => Promise; context: BrowserContext; page: Page; }