Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
docs: explain how to reset options (#35790)
Dmitry Gozman0766aa9afb00
diff --git a/docs/src/test-fixtures-js.md b/docs/src/test-fixtures-js.mdindex 5ffc26d01c..19fbf687c1 100644--- a/docs/src/test-fixtures-js.md+++ b/docs/src/test-fixtures-js.md@@ -575,6 +575,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 orderEach 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/docs/src/test-use-options-js.md b/docs/src/test-use-options-js.mdindex 12f97db46d..0b46393941 100644--- a/docs/src/test-use-options-js.md+++ b/docs/src/test-use-options-js.md@@ -192,7 +192,7 @@ export default defineConfig({### More browser and context options-Any options accepted by [`method: BrowserType.launch`] or [`method: Browser.newContext`] can be put into `launchOptions` or `contextOptions` respectively in the `use` section.+Any options accepted by [`method: BrowserType.launch`], [`method: Browser.newContext`] or [`method: BrowserType.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,3 +296,54 @@ 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.+});+```