From ef33ce26bd3de9d5521773bd8ae858cafd846a1f Mon Sep 17 00:00:00 2001 From: "microsoft-playwright-automation[bot]" <203992400+microsoft-playwright-automation[bot]@users.noreply.github.com> Date: Tue, 29 Apr 2025 12:33:12 +0000 Subject: [PATCH] feat(roll): roll to ToT Playwright (29-04-25) --- nodejs/docs/test-fixtures.mdx | 51 ++++++++++++++++++++++++++++++ nodejs/docs/test-reporters.mdx | 1 + nodejs/docs/test-use-options.mdx | 53 +++++++++++++++++++++++++++++++- 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/nodejs/docs/test-fixtures.mdx b/nodejs/docs/test-fixtures.mdx index 0b8cd17d8b1..8072c89e237 100644 --- a/nodejs/docs/test-fixtures.mdx +++ b/nodejs/docs/test-fixtures.mdx @@ -590,6 +590,57 @@ test.use({ }); ``` +**Reset an option** + +You can reset an option to the value defined in the config file by setting it to `undefined`. Consider the following config that sets a `baseURL`: + +```js title="playwright.config.ts" +import { defineConfig } from '@playwright/test'; + +export default defineConfig({ + use: { + baseURL: 'https://playwright.dev', + }, +}); +``` + +You can now configure `baseURL` for a file, and also opt-out for a single test. + +```js title="intro.spec.ts" +import { test } from '@playwright/test'; + +// Configure baseURL for this file. +test.use({ baseURL: 'https://playwright.dev/docs/intro' }); + +test('check intro contents', async ({ page }) => { + // This test will use "https://playwright.dev/docs/intro" base url as defined above. +}); + +test.describe(() => { + // Reset the value to a config-defined one. + test.use({ baseURL: undefined }); + + test('can navigate to intro from the home page', async ({ page }) => { + // This test will use "https://playwright.dev" base url as defined in the config. + }); +}); +``` + +If you would like to completely reset the value to `undefined`, use a long-form fixture notation. + +```js title="intro.spec.ts" +import { test } from '@playwright/test'; + +// Completely unset baseURL for this file. +test.use({ + baseURL: [async ({}, use) => use(undefined), { scope: 'test' }], +}); + +test('no base url', async ({ page }) => { + // This test will not have a base url. +}); +``` + ## Execution order Each fixture has a setup and teardown phase before and after the `await use()` call in the fixture. Setup is executed before the test/hook requiring it is run, and teardown is executed when the fixture is no longer being used by the test/hook. diff --git a/nodejs/docs/test-reporters.mdx b/nodejs/docs/test-reporters.mdx index f563da2428a..18008654dd4 100644 --- a/nodejs/docs/test-reporters.mdx +++ b/nodejs/docs/test-reporters.mdx @@ -246,6 +246,7 @@ HTML report supports the following configuration options and environment variabl | Environment Variable Name | Reporter Config Option| Description | Default |---|---|---|---| +| `PLAYWRIGHT_HTML_TITLE` | `title` | A title to display in the generated report. | No title is displayed by default | `PLAYWRIGHT_HTML_OUTPUT_DIR` | `outputFolder` | Directory to save the report to. | `playwright-report` | `PLAYWRIGHT_HTML_OPEN` | `open` | When to open the html report in the browser, one of `'always'`, `'never'` or `'on-failure'` | `'on-failure'` | `PLAYWRIGHT_HTML_HOST` | `host` | When report opens in the browser, it will be served bound to this hostname. | `localhost` diff --git a/nodejs/docs/test-use-options.mdx b/nodejs/docs/test-use-options.mdx index f0eb76db0ba..a5b69e9f8d1 100644 --- a/nodejs/docs/test-use-options.mdx +++ b/nodejs/docs/test-use-options.mdx @@ -192,7 +192,7 @@ export default defineConfig({ ### More browser and context options -Any options accepted by [browserType.launch()](/api/class-browsertype.mdx#browser-type-launch) or [browser.newContext()](/api/class-browser.mdx#browser-new-context) can be put into `launchOptions` or `contextOptions` respectively in the `use` section. +Any options accepted by [browserType.launch()](/api/class-browsertype.mdx#browser-type-launch), [browser.newContext()](/api/class-browser.mdx#browser-new-context) or [browserType.connect()](/api/class-browsertype.mdx#browser-type-connect) can be put into `launchOptions`, `contextOptions` or `connectOptions` respectively in the `use` section. ```js title="playwright.config.ts" import { defineConfig } from '@playwright/test'; @@ -296,6 +296,57 @@ test.describe('french language block', () => { }); ``` +### Reset an option + +You can reset an option to the value defined in the config file. Consider the following config that sets a `baseURL`: + +```js title="playwright.config.ts" +import { defineConfig } from '@playwright/test'; + +export default defineConfig({ + use: { + baseURL: 'https://playwright.dev', + }, +}); +``` + +You can now configure `baseURL` for a file, and also opt-out for a single test. + +```js title="intro.spec.ts" +import { test } from '@playwright/test'; + +// Configure baseURL for this file. +test.use({ baseURL: 'https://playwright.dev/docs/intro' }); + +test('check intro contents', async ({ page }) => { + // This test will use "https://playwright.dev/docs/intro" base url as defined above. +}); + +test.describe(() => { + // Reset the value to a config-defined one. + test.use({ baseURL: undefined }); + + test('can navigate to intro from the home page', async ({ page }) => { + // This test will use "https://playwright.dev" base url as defined in the config. + }); +}); +``` + +If you would like to completely reset the value to `undefined`, use a long-form fixture notation. + +```js title="intro.spec.ts" +import { test } from '@playwright/test'; + +// Completely unset baseURL for this file. +test.use({ + baseURL: [async ({}, use) => use(undefined), { scope: 'test' }], +}); + +test('no base url', async ({ page }) => { + // This test will not have a base url. +}); +``` + [Accessibility]: /api/class-accessibility.mdx "Accessibility" [Android]: /api/class-android.mdx "Android"