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
chore: generate usage: sections based on snippets (#18965)
Pavel Feldman620e8547d41e
diff --git a/docs/src/api/class-accessibility.md b/docs/src/api/class-accessibility.mdindex 7230f05588..dce0b8cc85 100644--- a/docs/src/api/class-accessibility.md+++ b/docs/src/api/class-accessibility.md@@ -58,6 +58,8 @@ The Chromium accessibility tree contains nodes that go unused on most platformswill discard them as well for an easier to process tree, unless [`option: interestingOnly`] is set to `false`.:::+**Usage**+An example of dumping the entire accessibility tree:```jsdiff --git a/docs/src/api/class-android.md b/docs/src/api/class-android.mdindex 88f003e331..67b96c331a 100644--- a/docs/src/api/class-android.md+++ b/docs/src/api/class-android.md@@ -140,6 +140,8 @@ Prevents automatic playwright driver installation on attach. Assumes that the drLaunches Playwright Android server that clients can connect to. See the following example:+**Usage**+Server Side:```jsdiff --git a/docs/src/api/class-apirequestcontext.md b/docs/src/api/class-apirequestcontext.mdindex 932b5e198c..4a5debdb14 100644--- a/docs/src/api/class-apirequestcontext.md+++ b/docs/src/api/class-apirequestcontext.md@@ -188,9 +188,9 @@ discards all stored responses, and makes [`method: APIResponse.body`] throw "Res- returns: <[APIResponse]>Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update-context cookies from the response. The method will automatically follow redirects.+context cookies from the response. The method will automatically follow redirects. JSON objects can be passed directly to the request.-JSON objects can be passed directly to the request:+**Usage**```jsawait request.fetch('https://example.com/api/createBook', {@@ -351,6 +351,8 @@ Sends HTTP(S) [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GEThe method will populate request cookies from the context and updatecontext cookies from the response. The method will automatically follow redirects.+**Usage**+Request parameters can be configured with `params` option, they will be serialized into the URL search parameters:```js@@ -535,6 +537,8 @@ Sends HTTP(S) [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PThe method will populate request cookies from the context and updatecontext cookies from the response. The method will automatically follow redirects.+**Usage**+JSON objects can be passed directly to the request:```jsdiff --git a/docs/src/api/class-apiresponseassertions.md b/docs/src/api/class-apiresponseassertions.mdindex c045ae679f..b46565f0ad 100644--- a/docs/src/api/class-apiresponseassertions.md+++ b/docs/src/api/class-apiresponseassertions.md@@ -74,6 +74,8 @@ The opposite of [`method: APIResponseAssertions.toBeOK`].Ensures the response status code is within `200..299` range.+**Usage**+```jsawait expect(response).toBeOK();```diff --git a/docs/src/api/class-browser.md b/docs/src/api/class-browser.mdindex e77cbfaa83..bb516be613 100644--- a/docs/src/api/class-browser.md+++ b/docs/src/api/class-browser.md@@ -108,6 +108,8 @@ The [Browser] object itself is considered to be disposed and cannot be used anymReturns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.+**Usage**+```jsconst browser = await pw.webkit.launch();console.log(browser.contexts().length); // prints `0`@@ -173,6 +175,8 @@ If directly using this method to create [BrowserContext]s, it is best practice tand before calling [`method: Browser.close`]. This will ensure the `context` is closed gracefully and any artifacts—like HARs and videos—are fully flushed and saved.:::+**Usage**+```js(async () => {const browser = await playwright.firefox.launch(); // Or 'chromium' or 'webkit'.@@ -292,6 +296,8 @@ This API controls [Chromium Tracing](https://www.chromium.org/developers/how-tosYou can use [`method: Browser.startTracing`] and [`method: Browser.stopTracing`] to create a trace file that canbe opened in Chrome DevTools performance panel.+**Usage**+```jsawait browser.startTracing(page, {path: 'trace.json'});await page.goto('https://www.google.com');diff --git a/docs/src/api/class-browsercontext.md b/docs/src/api/class-browsercontext.mdindex e4d1fbee89..82f9c4ec41 100644--- a/docs/src/api/class-browsercontext.md+++ b/docs/src/api/class-browsercontext.md@@ -203,6 +203,8 @@ Emitted when new service worker is created in the context.Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can beobtained via [`method: BrowserContext.cookies`].+**Usage**+```jsawait browserContext.addCookies([cookieObject1, cookieObject2]);```@@ -247,6 +249,8 @@ Adds a script which would be evaluated in one of the following scenarios:The script is evaluated after the document was created but before any of its scripts were run. This is useful to amendthe JavaScript environment, e.g. to seed `Math.random`.+**Usage**+An example of overriding `Math.random` before the page loads:```js browser@@ -336,6 +340,8 @@ Clears context cookies.Clears all permission overrides for the browser context.+**Usage**+```jsconst context = await browser.newContext();await context.grantPermissions(['clipboard-read']);@@ -415,6 +421,8 @@ BrowserContext, page: Page, frame: Frame }`.See [`method: Page.exposeBinding`] for page-only version.+**Usage**+An example of exposing page URL to all frames in all pages in the context:```js@@ -639,6 +647,8 @@ If the [`param: callback`] returns a [Promise], it will be awaited.See [`method: Page.exposeFunction`] for page-only version.+**Usage**+An example of adding a `sha256` function to all pages in the context:```js@@ -894,6 +904,8 @@ is enabled, every request matching the url pattern will stall unless it's contin[`method: BrowserContext.route`] will not intercept requests intercepted by Service Worker. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting [`option: Browser.newContext.serviceWorkers`] to `'block'`.:::+**Usage**+An example of a naive handler that aborts all image requests:```js@@ -1170,6 +1182,8 @@ An object containing additional HTTP headers to be sent with every request. AllSets the context's geolocation. Passing `null` or `undefined` emulates position unavailable.+**Usage**+```jsawait browserContext.setGeolocation({latitude: 59.95, longitude: 30.31667});```@@ -1295,6 +1309,8 @@ Optional handler function used to register a routing with [`method: BrowserConteWaits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthyvalue. Will throw an error if the context closes before the event is fired. Returns the event data value.+**Usage**+```jsconst [page, _] = await Promise.all([context.waitForEvent('page'),diff --git a/docs/src/api/class-browsertype.md b/docs/src/api/class-browsertype.mdindex a9b229b7db..99bff95ded 100644--- a/docs/src/api/class-browsertype.md+++ b/docs/src/api/class-browsertype.md@@ -136,6 +136,8 @@ The default browser context is accessible via [`method: Browser.contexts`].Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.:::+**Usage**+```jsconst browser = await playwright.chromium.connectOverCDP('http://localhost:9222');const defaultContext = browser.contexts()[0];@@ -218,6 +220,8 @@ A path where Playwright expects to find a bundled browser executable.Returns the browser instance.+**Usage**+You can use [`option: ignoreDefaultArgs`] to filter out `--mute-audio` from default arguments:```js@@ -324,6 +328,8 @@ use a temporary directory instead.Returns the browser app instance. You can connect to it via [`method: BrowserType.connect`], which requires the major/minor client/server version to match (1.2.3 → is compatible with 1.2.x).+**Usage**+Launches browser server that client can connect to. An example of launching a browser executable and connecting to itlater:diff --git a/docs/src/api/class-electronapplication.md b/docs/src/api/class-electronapplication.mdindex 5b661ccb49..a672697506 100644--- a/docs/src/api/class-electronapplication.md+++ b/docs/src/api/class-electronapplication.md@@ -118,7 +118,8 @@ Optional argument to pass to [`param: expression`].- returns: <[Page]>Convenience method that waits for the first application window to be opened.-Typically your script will start with:++**Usage**```jsconst electronApp = await electron.launch({@@ -140,6 +141,8 @@ Returns the main process for this Electron Application.Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value. Will throw an error if the application is closed before the event is fired. Returns the event data value.+**Usage**+```jsconst [window] = await Promise.all([electronApp.waitForEvent('window'),diff --git a/docs/src/api/class-elementhandle.md b/docs/src/api/class-elementhandle.mdindex 295acb425d..2861d04abe 100644--- a/docs/src/api/class-elementhandle.md+++ b/docs/src/api/class-elementhandle.md@@ -127,6 +127,8 @@ Elements from child frames return the bounding box relative to the main frame, uAssuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the followingsnippet should click the center of the element.+**Usage**+```jsconst box = await elementHandle.boundingBox();await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);@@ -283,6 +285,8 @@ The snippet below dispatches the `click` event on the element. Regardless of theis dispatched. This is equivalent to calling[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).+**Usage**+```jsawait elementHandle.dispatchEvent('click');```@@ -381,7 +385,7 @@ details. If no elements match the selector, the method throws an error.If [`param: expression`] returns a [Promise], then [`method: ElementHandle.evalOnSelector`] would wait for the promise to resolve and return itsvalue.-Examples:+**Usage**```jsconst tweetHandle = await page.$('.tweet');@@ -441,7 +445,7 @@ matched elements as a first argument to [`param: expression`]. SeeIf [`param: expression`] returns a [Promise], then [`method: ElementHandle.evalOnSelectorAll`] would wait for the promise to resolve and return itsvalue.-Examples:+**Usage**```html<div class="feed">@@ -733,6 +737,8 @@ Returns the array of option values that have been successfully selected.Triggers a `change` and `input` event once all the provided options have been selected.+**Usage**+```js// single selection matching the valuehandle.selectOption('blue');@@ -912,6 +918,8 @@ Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup`To press a special key, like `Control` or `ArrowDown`, use [`method: ElementHandle.press`].+**Usage**+```jsawait elementHandle.type('Hello'); // Types instantlyawait elementHandle.type('World', {delay: 100}); // Types slower, like a user@@ -1058,6 +1066,8 @@ appear/disappear from dom, or become visible/hidden). If at the moment of callinsatisfies the condition, the method will return immediately. If the selector doesn't satisfy the condition for the[`option: timeout`] milliseconds, the function will throw.+**Usage**+```jsawait page.setContent(`<div><span></span></div>`);const div = await page.$('div');diff --git a/docs/src/api/class-frame.md b/docs/src/api/class-frame.mdindex db137da96c..43c51065a9 100644--- a/docs/src/api/class-frame.md+++ b/docs/src/api/class-frame.md@@ -342,6 +342,8 @@ The snippet below dispatches the `click` event on the element. Regardless of theis dispatched. This is equivalent to calling[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).+**Usage**+```jsawait frame.dispatchEvent('button#submit', 'click');```@@ -482,7 +484,7 @@ elements match the selector, the method throws an error.If [`param: expression`] returns a [Promise], then [`method: Frame.evalOnSelector`] would wait for the promise to resolve and return itsvalue.-Examples:+**Usage**```jsconst searchValue = await frame.$eval('#search', el => el.value);@@ -549,7 +551,7 @@ more details.If [`param: expression`] returns a [Promise], then [`method: Frame.evalOnSelectorAll`] would wait for the promise to resolve and return itsvalue.-Examples:+**Usage**```jsconst divsCounts = await frame.$$eval('div', (divs, min) => divs.length >= min, 10);@@ -596,6 +598,8 @@ If the function passed to the [`method: Frame.evaluate`] returns a non-[Serializ[`method: Frame.evaluate`] returns `undefined`. Playwright also supports transferring someadditional values that are not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.+**Usage**+```jsconst result = await frame.evaluate(([x, y]) => {return Promise.resolve(x * y);@@ -704,6 +708,8 @@ The only difference between [`method: Frame.evaluate`] and [`method: Frame.evaluIf the function, passed to the [`method: Frame.evaluateHandle`], returns a [Promise], then[`method: Frame.evaluateHandle`] would wait for the promise to resolve and return its value.+**Usage**+```jsconst aWindowHandle = await frame.evaluateHandle(() => Promise.resolve(window));aWindowHandle; // Handle for the window object.@@ -853,6 +859,8 @@ frame.This method throws an error if the frame has been detached before `frameElement()` returns.+**Usage**+```jsconst frameElement = await frame.frameElement();const contentFrame = await frameElement.contentFrame();@@ -888,8 +896,11 @@ Console.WriteLine(frame == contentFrame); // -> True- returns: <[FrameLocator]>When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements-in that iframe. Following snippet locates element with text "Submit" in the iframe with id `my-frame`,-like `<iframe id="my-frame">`:+in that iframe.++**Usage**++Following snippet locates element with text "Submit" in the iframe with id `my-frame`, like `<iframe id="my-frame">`:```jsconst locator = frame.frameLocator('#my-iframe').getByText('Submit');@@ -1387,6 +1398,8 @@ Returns the array of option values that have been successfully selected.Triggers a `change` and `input` event once all the provided options have been selected.+**Usage**+```js// single selection matching the valueframe.selectOption('select#colors', 'blue');@@ -1605,6 +1618,8 @@ send fine-grained keyboard events. To fill values in form fields, use [`method:To press a special key, like `Control` or `ArrowDown`, use [`method: Keyboard.press`].+**Usage**+```jsawait frame.type('#mytextarea', 'Hello'); // Types instantlyawait frame.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user@@ -1707,6 +1722,8 @@ Returns frame's url.Returns when the [`param: expression`] returns a truthy value, returns that value.+**Usage**+The [`method: Frame.waitForFunction`] can be used to observe viewport size change:```js@@ -1842,6 +1859,8 @@ Waits for the required load state to be reached.This returns when the frame reaches a required load state, `load` by default. The navigation must have been committedwhen this method is called. If current document has already reached the required state, resolves immediately.+**Usage**+```jsawait frame.click('button'); // Click triggers navigation.await frame.waitForLoadState(); // Waits for 'load' state by default.@@ -1884,6 +1903,8 @@ Waits for the frame navigation and returns the main resource response. In case owill resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due toHistory API usage, the navigation will resolve with `null`.+**Usage**+This method waits for the frame to navigate to a new URL. It is useful for when you run code which will indirectly causethe frame to navigate. Consider this example:@@ -1955,6 +1976,8 @@ visible/hidden). If at the moment of calling the method [`param: selector`] alrewill return immediately. If the selector doesn't satisfy the condition for the [`option: timeout`] milliseconds, thefunction will throw.+**Usage**+This method works across navigations:```js@@ -2083,6 +2106,8 @@ A timeout to wait forWaits for the frame to navigate to the given URL.+**Usage**+```jsawait frame.click('a.delayed-navigation'); // Clicking the link will indirectly cause a navigationawait frame.waitForURL('**/target.html');diff --git a/docs/src/api/class-jshandle.md b/docs/src/api/class-jshandle.mdindex 37467beab0..f3bc9b19a1 100644--- a/docs/src/api/class-jshandle.md+++ b/docs/src/api/class-jshandle.md@@ -57,7 +57,7 @@ This method passes this handle as the first argument to [`param: expression`].If [`param: expression`] returns a [Promise], then `handle.evaluate` would wait for the promise to resolve and returnits value.-Examples:+**Usage**```jsconst tweetHandle = await page.$('.tweet .retweets');@@ -123,6 +123,8 @@ Optional argument to pass to [`param: expression`].The method returns a map with **own property names** as keys and JSHandle instances for the property values.+**Usage**+```jsconst handle = await page.evaluateHandle(() => ({window, document}));const properties = await handle.getProperties();diff --git a/docs/src/api/class-keyboard.md b/docs/src/api/class-keyboard.mdindex 87e41150bc..add5274745 100644--- a/docs/src/api/class-keyboard.md+++ b/docs/src/api/class-keyboard.md@@ -180,6 +180,8 @@ Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.Dispatches only `input` event, does not emit the `keydown`, `keyup` or `keypress` events.+**Usage**+```jspage.keyboard.insertText('嗨');```@@ -231,6 +233,8 @@ respective texts.Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with themodifier, modifier is pressed and being held while the subsequent key is being pressed.+**Usage**+```jsconst page = await browser.newPage();await page.goto('https://keycode.info');@@ -311,6 +315,8 @@ Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in tTo press a special key, like `Control` or `ArrowDown`, use [`method: Keyboard.press`].+**Usage**+```jsawait page.keyboard.type('Hello'); // Types instantlyawait page.keyboard.type('World', {delay: 100}); // Types slower, like a userdiff --git a/docs/src/api/class-locator.md b/docs/src/api/class-locator.mdindex 4dad1998a0..6b5286374f 100644--- a/docs/src/api/class-locator.md+++ b/docs/src/api/class-locator.md@@ -47,6 +47,8 @@ Elements from child frames return the bounding box relative to the main frame, uAssuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the followingsnippet should click the center of the element.+**Usage**+```jsconst box = await element.boundingBox();await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);@@ -222,6 +224,8 @@ The snippet below dispatches the `click` event on the element. Regardless of theis dispatched. This is equivalent to calling[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).+**Usage**+```jsawait element.dispatchEvent('click');```@@ -314,6 +318,8 @@ This method drags the locator to another target locator or target position. It wfirst move to the source element, perform a `mousedown`, then move to the targetelement or position and perform a `mouseup`.+**Usage**+```jsconst source = page.locator('#source');const target = page.locator('#target');@@ -425,7 +431,7 @@ This method passes this handle as the first argument to [`param: expression`].If [`param: expression`] returns a [Promise], then `handle.evaluate` would wait for the promise to resolve and returnits value.-Examples:+**Usage**```jsconst tweets = page.locator('.tweet .retweets');@@ -474,7 +480,7 @@ a first argument to [`param: expression`]. Returns the result of [`param: expresIf [`param: expression`] returns a [Promise], then [`method: Locator.evaluateAll`] would wait for the promiseto resolve and return its value.-Examples:+**Usage**```jsconst elements = page.locator('div');@@ -568,6 +574,8 @@ Value to set for the `<input>`, `<textarea>` or `[contenteditable]` element.This method narrows existing locator according to the options, for example filters by text.It can be chained to filter multiple times.+**Usage**+```jsconst rowLocator = page.locator('tr');// ...@@ -638,6 +646,8 @@ Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus* since: v1.17- returns: <[FrameLocator]>+**Usage**+When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elementsin that iframe:@@ -993,6 +1003,8 @@ Returns the array of option values that have been successfully selected.Triggers a `change` and `input` event once all the provided options have been selected.+**Usage**+```js// single selection matching the valueelement.selectOption('blue');@@ -1175,6 +1187,8 @@ Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup`To press a special key, like `Control` or `ArrowDown`, use [`method: Locator.press`].+**Usage**+```jsawait element.type('Hello'); // Types instantlyawait element.type('World', {delay: 100}); // Types slower, like a user@@ -1290,6 +1304,8 @@ Returns when element specified by locator satisfies the [`option: state`] optionIf target element already satisfies the condition, the method returns immediately. Otherwise, waits for up to[`option: timeout`] milliseconds until the condition is met.+**Usage**+```jsconst orderSent = page.locator('#order-sent');await orderSent.waitFor();diff --git a/docs/src/api/class-locatorassertions.md b/docs/src/api/class-locatorassertions.mdindex 1cc15e6c2e..dbc3781782 100644--- a/docs/src/api/class-locatorassertions.md+++ b/docs/src/api/class-locatorassertions.md@@ -423,6 +423,8 @@ Expected options currently selected.Ensures the [Locator] points to a checked input.+**Usage**+```jsconst locator = page.getByLabel('Subscribe to newsletter');await expect(locator).toBeChecked();@@ -472,6 +474,8 @@ Note that only native control elements such as HTML `button`, `input`, `select`,can be disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignoredby the browser.+**Usage**+```jsconst locator = page.locator('button.submit');await expect(locator).toBeDisabled();@@ -513,6 +517,8 @@ await Expect(locator).ToBeDisabledAsync();Ensures the [Locator] points to an editable element.+**Usage**+```jsconst locator = page.getByRole('textbox');await expect(locator).toBeEditable();@@ -558,6 +564,8 @@ await Expect(locator).ToBeEditableAsync();Ensures the [Locator] points to an empty editable element or to a DOM node that has no text.+**Usage**+```jsconst locator = page.locator('div.warning');await expect(locator).toBeEmpty();@@ -599,6 +607,8 @@ await Expect(locator).ToBeEmptyAsync();Ensures the [Locator] points to an enabled element.+**Usage**+```jsconst locator = page.locator('button.submit');await expect(locator).toBeEnabled();@@ -644,6 +654,8 @@ await Expect(locator).toBeEnabledAsync();Ensures the [Locator] points to a focused DOM node.+**Usage**+```jsconst locator = page.getByRole('textbox');await expect(locator).toBeFocused();@@ -685,6 +697,8 @@ await Expect(locator).ToBeFocusedAsync();Ensures that [Locator] either does not resolve to any DOM node, or resolves to a [non-visible](./actionability.md#visible) one.+**Usage**+```jsconst locator = page.locator('.my-element');await expect(locator).toBeHidden();@@ -726,6 +740,8 @@ await Expect(locator).ToBeHiddenAsync();Ensures that [Locator] points to an [attached](./actionability.md#attached) and [visible](./actionability.md#visible) DOM node.+**Usage**+```jsconst locator = page.locator('.my-element');await expect(locator).toBeVisible();@@ -771,6 +787,8 @@ await Expect(locator).ToBeVisibleAsync();Ensures the [Locator] points to an element that contains the given text. You can use regular expressions for the value as well.+**Usage**+```jsconst locator = page.locator('.title');await expect(locator).toContainText('substring');@@ -936,6 +954,8 @@ Whether to use `element.innerText` instead of `element.textContent` when retrievEnsures the [Locator] points to an element with given attribute.+**Usage**+```jsconst locator = page.locator('input');await expect(locator).toHaveAttribute('type', 'text');@@ -990,6 +1010,8 @@ Expected attribute value.Ensures the [Locator] points to an element with given CSS classes. This needs to be a full matchor using a relaxed regular expression.+**Usage**+```html<div class='selected row' id='component'></div>```@@ -1084,6 +1106,8 @@ Expected class or RegExp or a list of those.Ensures the [Locator] resolves to an exact number of DOM nodes.+**Usage**+```jsconst list = page.locator('list > .component');await expect(list).toHaveCount(3);@@ -1131,6 +1155,8 @@ Expected count.Ensures the [Locator] resolves to an element with the given computed CSS style.+**Usage**+```jsconst locator = page.getByRole('button');await expect(locator).toHaveCSS('display', 'flex');@@ -1184,6 +1210,8 @@ CSS property value.Ensures the [Locator] points to an element with the given DOM Node ID.+**Usage**+```jsconst locator = page.getByRole('textbox');await expect(locator).toHaveId('lastname');@@ -1232,6 +1260,8 @@ Element id.Ensures the [Locator] points to an element with given JavaScript property. Note that this property can beof a primitive type as well as a plain serializable JavaScript object.+**Usage**+```jsconst locator = page.locator('.component');await expect(locator).toHaveJSProperty('loaded', true);@@ -1285,6 +1315,8 @@ Property value.This function will wait until two consecutive locator screenshotsyield the same result, and then compare the last screenshot with the expectation.+**Usage**+```jsconst locator = page.getByRole('button');await expect(locator).toHaveScreenshot('image.png');@@ -1330,6 +1362,8 @@ Snapshot name.This function will wait until two consecutive locator screenshotsyield the same result, and then compare the last screenshot with the expectation.+**Usage**+```jsconst locator = page.getByRole('button');await expect(locator).toHaveScreenshot();@@ -1369,6 +1403,8 @@ await expect(locator).toHaveScreenshot();Ensures the [Locator] points to an element with the given text. You can use regular expressions for the value as well.+**Usage**+```jsconst locator = page.locator('.title');await expect(locator).toHaveText(/Welcome, Test User/);@@ -1534,6 +1570,8 @@ Whether to use `element.innerText` instead of `element.textContent` when retrievEnsures the [Locator] points to an element with the given input value. You can use regular expressions for the value as well.+**Usage**+```jsconst locator = page.locator('input[type=number]');await expect(locator).toHaveValue(/[0-9]/);@@ -1583,6 +1621,8 @@ Expected value.Ensures the [Locator] points to multi-select/combobox (i.e. a `select` with the `multiple` attribute) and the specified values are selected.+**Usage**+For example, given the following element:```htmldiff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.mdindex 165efdbf62..3249eafcec 100644--- a/docs/src/api/class-page.md+++ b/docs/src/api/class-page.md@@ -573,6 +573,8 @@ Adds a script which would be evaluated in one of the following scenarios:The script is evaluated after the document was created but before any of its scripts were run. This is useful to amendthe JavaScript environment, e.g. to seed `Math.random`.+**Usage**+An example of overriding `Math.random` before the page loads:```js browser@@ -896,6 +898,8 @@ The snippet below dispatches the `click` event on the element. Regardless of theis dispatched. This is equivalent to calling[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).+**Usage**+```jsawait page.dispatchEvent('button#submit', 'click');```@@ -991,6 +995,8 @@ This method drags the source element to the target element.It will first move to the source element, perform a `mousedown`,then move to the target element and perform a `mouseup`.+**Usage**+```jsawait page.dragAndDrop('#source', '#target');// or specify exact positions relative to the top-left corners of the elements:@@ -1071,6 +1077,8 @@ await Page.DragAndDropAsync("#source", "#target", new()This method changes the `CSS media type` through the `media` argument, and/or the `'prefers-colors-scheme'` media feature, using the `colorScheme` argument.+**Usage**+```jsawait page.evaluate(() => matchMedia('screen').matches);// → true@@ -1292,7 +1300,7 @@ The method finds an element matching the specified selector within the page andIf [`param: expression`] returns a [Promise], then [`method: Page.evalOnSelector`] would wait for the promise to resolve andreturn its value.-Examples:+**Usage**```jsconst searchValue = await page.$eval('#search', el => el.value);@@ -1360,7 +1368,7 @@ a first argument to [`param: expression`]. Returns the result of [`param: expresIf [`param: expression`] returns a [Promise], then [`method: Page.evalOnSelectorAll`] would wait for the promise to resolve andreturn its value.-Examples:+**Usage**```jsconst divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);@@ -1407,6 +1415,8 @@ If the function passed to the [`method: Page.evaluate`] returns a non-[Serializa[`method: Page.evaluate`] resolves to `undefined`. Playwright also supports transferring someadditional values that are not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.+**Usage**+Passing argument to [`param: expression`]:```js@@ -1520,6 +1530,8 @@ The only difference between [`method: Page.evaluate`] and [`method: Page.evaluatIf the function passed to the [`method: Page.evaluateHandle`] returns a [Promise], then [`method: Page.evaluateHandle`] would wait for thepromise to resolve and return its value.+**Usage**+```jsconst aWindowHandle = await page.evaluateHandle(() => Promise.resolve(window));aWindowHandle; // Handle for the window object.@@ -1629,6 +1641,8 @@ See [`method: BrowserContext.exposeBinding`] for the context-wide version.Functions installed via [`method: Page.exposeBinding`] survive navigations.:::+**Usage**+An example of exposing page URL to all frames in a page:```js@@ -1863,6 +1877,8 @@ See [`method: BrowserContext.exposeFunction`] for context-wide exposed function.Functions installed via [`method: Page.exposeFunction`] survive navigations.:::+**Usage**+An example of adding a `sha256` function to the page:```js@@ -2091,6 +2107,8 @@ Shortcut for main frame's [`method: Frame.focus`].Returns frame matching the specified criteria. Either `name` or `url` must be specified.+**Usage**+```jsconst frame = page.frame('frame-name');```@@ -2159,7 +2177,11 @@ A glob pattern, regex pattern or predicate receiving frame's `url` as a [URL] ob- returns: <[FrameLocator]>When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements-in that iframe. Following snippet locates element with text "Submit" in the iframe with id `my-frame`,+in that iframe.++**Usage**++Following snippet locates element with text "Submit" in the iframe with id `my-frame`,like `<iframe id="my-frame">`:```js@@ -2627,6 +2649,8 @@ By default, `page.pdf()` generates a pdf with modified colors for printing. Useforce rendering of exact colors.:::+**Usage**+```js// Generates a PDF with 'screen' media type.await page.emulateMedia({media: 'screen'});@@ -2831,6 +2855,8 @@ respective texts.Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with themodifier, modifier is pressed and being held while the subsequent key is being pressed.+**Usage**+```jsconst page = await browser.newPage();await page.goto('https://keycode.info');@@ -2992,6 +3018,8 @@ The handler will only be called for the first url if the response is a redirect.[`method: Page.route`] will not intercept requests intercepted by Service Worker. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting [`option: Browser.newContext.serviceWorkers`] to `'block'`.:::+**Usage**+An example of a naive handler that aborts all image requests:```js@@ -3209,6 +3237,8 @@ Returns the array of option values that have been successfully selected.Triggers a `change` and `input` event once all the provided options have been selected.+**Usage**+```js// single selection matching the valuepage.selectOption('select#colors', 'blue');@@ -3422,6 +3452,8 @@ In the case of multiple pages in a single browser, each page can have its own vi[`method: Page.setViewportSize`] will resize the page. A lot of websites don't expect phones to change size, so you should set theviewport size before navigating to the page. [`method: Page.setViewportSize`] will also reset `screen` size, use [`method: Browser.newContext`] with `screen` and `viewport` parameters if you need better control of these properties.+**Usage**+```jsconst page = await browser.newPage();await page.setViewportSize({@@ -3550,6 +3582,8 @@ fine-grained keyboard events. To fill values in form fields, use [`method: Page.To press a special key, like `Control` or `ArrowDown`, use [`method: Keyboard.press`].+**Usage**+```jsawait page.type('#mytextarea', 'Hello'); // Types instantlyawait page.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user@@ -3747,6 +3781,8 @@ Receives the [Download] object and resolves to truthy value when the waiting shoWaits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthyvalue. Will throw an error if the page is closed before the event is fired. Returns the event data value.+**Usage**+```js// Note that Promise.all prevents a race condition// between clicking and waiting for the event.@@ -3809,6 +3845,8 @@ Receives the [FileChooser] object and resolves to truthy value when the waitingReturns when the [`param: expression`] returns a truthy value. It resolves to a JSHandle of the truthy value.+**Usage**+The [`method: Page.waitForFunction`] can be used to observe viewport size change:```js@@ -3946,6 +3984,8 @@ Returns when the required load state has been reached.This resolves when the page reaches a required load state, `load` by default. The navigation must have been committedwhen this method is called. If current document has already reached the required state, resolves immediately.+**Usage**+```jsawait page.getByRole('button').click(); // Click triggers navigation.await page.waitForLoadState(); // The promise resolves after 'load' event.@@ -4036,6 +4076,8 @@ Waits for the main frame navigation and returns the main resource response. In cwill resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due toHistory API usage, the navigation will resolve with `null`.+**Usage**+This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will indirectlycause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from a `setTimeout`.Consider this example:@@ -4125,6 +4167,8 @@ Receives the [Page] object and resolves to truthy value when the waiting shouldWaits for the matching request and returns it. See [waiting for event](../events.md#waiting-for-event) for more details about events.+**Usage**+```js// Note that Promise.all prevents a race condition// between clicking and waiting for the request.@@ -4248,6 +4292,8 @@ Receives the [Request] object and resolves to truthy value when the waiting shouReturns the matched response. See [waiting for event](../events.md#waiting-for-event) for more details about events.+**Usage**+```js// Note that Promise.all prevents a race condition// between clicking and waiting for the response.@@ -4365,6 +4411,8 @@ visible/hidden). If at the moment of calling the method [`param: selector`] alrewill return immediately. If the selector doesn't satisfy the condition for the [`option: timeout`] milliseconds, thefunction will throw.+**Usage**+This method works across navigations:```js@@ -4484,6 +4532,8 @@ Waits for the given [`param: timeout`] in milliseconds.Note that `page.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going to beflaky. Use signals such as network events, selectors becoming visible and others instead.+**Usage**+```js// wait for 1 secondawait page.waitForTimeout(1000);@@ -4522,6 +4572,8 @@ A timeout to wait forWaits for the main frame to navigate to the given URL.+**Usage**+```jsawait page.click('a.delayed-navigation'); // Clicking the link will indirectly cause a navigationawait page.waitForURL('**/target.html');diff --git a/docs/src/api/class-pageassertions.md b/docs/src/api/class-pageassertions.mdindex 6ee2306d6f..664df6ed9c 100644--- a/docs/src/api/class-pageassertions.md+++ b/docs/src/api/class-pageassertions.md@@ -132,6 +132,8 @@ Expected URL string or RegExp.This function will wait until two consecutive page screenshotsyield the same result, and then compare the last screenshot with the expectation.+**Usage**+```jsawait expect(page).toHaveScreenshot('image.png');```@@ -182,6 +184,8 @@ Snapshot name.This function will wait until two consecutive page screenshotsyield the same result, and then compare the last screenshot with the expectation.+**Usage**+```jsawait expect(page).toHaveScreenshot();```@@ -226,6 +230,8 @@ await expect(page).toHaveScreenshot();Ensures the page has the given title.+**Usage**+```jsawait expect(page).toHaveTitle(/.*checkout/);```@@ -273,6 +279,8 @@ Expected title or RegExp.Ensures the page is navigated to the given URL.+**Usage**+```jsawait expect(page).toHaveURL(/.*checkout/);```diff --git a/docs/src/api/class-playwrightassertions.md b/docs/src/api/class-playwrightassertions.mdindex 6abe22ecc5..62f12df971 100644--- a/docs/src/api/class-playwrightassertions.md+++ b/docs/src/api/class-playwrightassertions.md@@ -84,6 +84,8 @@ By default, the timeout for assertions is set to 5 seconds.Creates a [APIResponseAssertions] object for the given [APIResponse].+**Usage**+```javaPlaywrightAssertions.assertThat(response).isOK();```@@ -105,6 +107,8 @@ PlaywrightAssertions.assertThat(response).isOK();Creates a [LocatorAssertions] object for the given [Locator].+**Usage**+```javaPlaywrightAssertions.assertThat(locator).isVisible();```@@ -130,6 +134,8 @@ await Expect(locator).ToBeVisibleAsync();Creates a [PageAssertions] object for the given [Page].+**Usage**+```javaPlaywrightAssertions.assertThat(page).hasTitle("News");```@@ -150,6 +156,8 @@ await Expect(page).ToHaveTitleAsync("News");Changes default timeout for Playwright assertions from 5 seconds to the specified value.+**Usage**+```javaPlaywrightAssertions.setDefaultAssertionTimeout(30_000);```diff --git a/docs/src/api/class-request.md b/docs/src/api/class-request.mdindex 1929beb4af..2c8793ce7b 100644--- a/docs/src/api/class-request.md+++ b/docs/src/api/class-request.md@@ -29,6 +29,8 @@ An object with all the request HTTP headers associated with this request. The heThe method returns `null` unless this request has failed, as reported by `requestfailed` event.+**Usage**+Example of logging of all the failed requests:```js@@ -133,6 +135,8 @@ When the server responds with a redirect, Playwright creates a new [Request] obj`redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible toconstruct the whole redirect chain by repeatedly calling `redirectedFrom()`.+**Usage**+For example, if the website `http://example.com` redirects to `https://example.com`:```js@@ -193,6 +197,8 @@ Console.WriteLine(response.Request.RedirectedFrom?.Url); // nullNew request issued by the browser if the server responded with redirect.+**Usage**+This method is the opposite of [`method: Request.redirectedFrom`]:```js@@ -272,6 +278,8 @@ Returns resource timing information for given request. Most of the timing values`responseEnd` becomes available when request finishes. Find more information at[Resource Timing API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming).+**Usage**+```jsconst [request] = await Promise.all([page.waitForEvent('requestfinished'),diff --git a/docs/src/api/class-route.md b/docs/src/api/class-route.mdindex 8b60f563a5..52ff8229eb 100644--- a/docs/src/api/class-route.md+++ b/docs/src/api/class-route.md@@ -41,6 +41,8 @@ Optional error code. Defaults to `failed`, could be one of the following:Continues route's request with optional overrides.+**Usage**+```jsawait page.route('**/*', (route, request) => {// Override headers@@ -138,6 +140,8 @@ That way the last registered route can always override all the previous ones. Inrequest will be handled by the bottom-most handler first, then it'll fall back to the previous one andin the end will be aborted by the first registered route.+**Usage**+```jsawait page.route('**/*', route => {// Runs last.@@ -409,6 +413,8 @@ If set changes the request HTTP headers. Header values will be converted to a stFulfills route's request with given response.+**Usage**+An example of fulfilling all requests with 404 responses:```jsdiff --git a/docs/src/api/class-screenshotassertions.md b/docs/src/api/class-screenshotassertions.mdindex bafc3b862f..1a2454d836 100644--- a/docs/src/api/class-screenshotassertions.md+++ b/docs/src/api/class-screenshotassertions.md@@ -14,6 +14,8 @@ expect(screenshot).toMatchSnapshot('landing-page.png');Ensures that passed value, either a [string] or a [Buffer], matches the expected snapshot stored in the test snapshots directory.+**Usage**+```js// Basic usage.expect(await page.screenshot()).toMatchSnapshot('landing-page.png');@@ -53,6 +55,8 @@ Snapshot name.Ensures that passed value, either a [string] or a [Buffer], matches the expected snapshot stored in the test snapshots directory.+**Usage**+```js// Basic usage and the file name is derived from the test name.expect(await page.screenshot()).toMatchSnapshot();diff --git a/docs/src/api/class-selectors.md b/docs/src/api/class-selectors.mdindex d6fe8381fd..3d6c3874b6 100644--- a/docs/src/api/class-selectors.md+++ b/docs/src/api/class-selectors.md@@ -7,6 +7,8 @@ information.## async method: Selectors.register* since: v1.8+**Usage**+An example of registering selector engine that queries elements based on a tag name:```jsdiff --git a/docs/src/api/class-tracing.md b/docs/src/api/class-tracing.mdindex 269636c852..49b0e02215 100644--- a/docs/src/api/class-tracing.md+++ b/docs/src/api/class-tracing.md@@ -65,6 +65,8 @@ await context.Tracing.StopAsync(new()Start tracing.+**Usage**+```jsawait context.tracing.start({ screenshots: true, snapshots: true });const page = await context.newPage();@@ -161,6 +163,8 @@ Trace name to be shown in the Trace Viewer.Start a new trace chunk. If you'd like to record multiple traces on the same [BrowserContext], use [`method: Tracing.start`] once, and then create multiple trace chunks with [`method: Tracing.startChunk`] and [`method: Tracing.stopChunk`].+**Usage**+```jsawait context.tracing.start({ screenshots: true, snapshots: true });const page = await context.newPage();diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.tsindex 82432bdb95..02c7ab2dc9 100644--- a/packages/playwright-core/types/types.d.ts+++ b/packages/playwright-core/types/types.d.ts@@ -88,6 +88,8 @@ export interface Page {* `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`:* `-0`, `NaN`, `Infinity`, `-Infinity`.*+ * **Usage**+ ** Passing argument to `pageFunction`:** ```js@@ -135,6 +137,8 @@ export interface Page {* `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`:* `-0`, `NaN`, `Infinity`, `-Infinity`.*+ * **Usage**+ ** Passing argument to `pageFunction`:** ```js@@ -183,6 +187,8 @@ export interface Page {* [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate-handle) would* wait for the promise to resolve and return its value.*+ * **Usage**+ ** ```js* const aWindowHandle = await page.evaluateHandle(() => Promise.resolve(window));* aWindowHandle; // Handle for the window object.@@ -223,6 +229,8 @@ export interface Page {* [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate-handle) would* wait for the promise to resolve and return its value.*+ * **Usage**+ ** ```js* const aWindowHandle = await page.evaluateHandle(() => Promise.resolve(window));* aWindowHandle; // Handle for the window object.@@ -258,6 +266,8 @@ export interface Page {* The script is evaluated after the document was created but before any of its scripts were run. This is useful to* amend the JavaScript environment, e.g. to seed `Math.random`.*+ * **Usage**+ ** An example of overriding `Math.random` before the page loads:** ```js@@ -342,7 +352,7 @@ export interface Page {* [page.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const searchValue = await page.$eval('#search', el => el.value);@@ -373,7 +383,7 @@ export interface Page {* [page.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const searchValue = await page.$eval('#search', el => el.value);@@ -404,7 +414,7 @@ export interface Page {* [page.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const searchValue = await page.$eval('#search', el => el.value);@@ -435,7 +445,7 @@ export interface Page {* [page.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const searchValue = await page.$eval('#search', el => el.value);@@ -466,7 +476,7 @@ export interface Page {* [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);@@ -489,7 +499,7 @@ export interface Page {* [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);@@ -512,7 +522,7 @@ export interface Page {* [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);@@ -535,7 +545,7 @@ export interface Page {* [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);@@ -550,6 +560,8 @@ export interface Page {/*** Returns when the `pageFunction` returns a truthy value. It resolves to a JSHandle of the truthy value.*+ * **Usage**+ ** The* [page.waitForFunction(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-wait-for-function)* can be used to observe viewport size change:@@ -586,6 +598,8 @@ export interface Page {/*** Returns when the `pageFunction` returns a truthy value. It resolves to a JSHandle of the truthy value.*+ * **Usage**+ ** The* [page.waitForFunction(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-wait-for-function)* can be used to observe viewport size change:@@ -631,6 +645,8 @@ export interface Page {* at the moment of calling the method `selector` already satisfies the condition, the method will return immediately.* If the selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.*+ * **Usage**+ ** This method works across navigations:** ```js@@ -663,6 +679,8 @@ export interface Page {* at the moment of calling the method `selector` already satisfies the condition, the method will return immediately.* If the selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.*+ * **Usage**+ ** This method works across navigations:** ```js@@ -695,6 +713,8 @@ export interface Page {* at the moment of calling the method `selector` already satisfies the condition, the method will return immediately.* If the selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.*+ * **Usage**+ ** This method works across navigations:** ```js@@ -727,6 +747,8 @@ export interface Page {* at the moment of calling the method `selector` already satisfies the condition, the method will return immediately.* If the selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.*+ * **Usage**+ ** This method works across navigations:** ```js@@ -765,6 +787,8 @@ export interface Page {* [page.exposeBinding(name, callback[, options])](https://playwright.dev/docs/api/class-page#page-expose-binding)* survive navigations.*+ * **Usage**+ ** An example of exposing page URL to all frames in a page:** ```js@@ -824,6 +848,8 @@ export interface Page {* [page.exposeBinding(name, callback[, options])](https://playwright.dev/docs/api/class-page#page-expose-binding)* survive navigations.*+ * **Usage**+ ** An example of exposing page URL to all frames in a page:** ```js@@ -2098,6 +2124,8 @@ export interface Page {* `click` is dispatched. This is equivalent to calling* [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).*+ * **Usage**+ ** ```js* await page.dispatchEvent('button#submit', 'click');* ```@@ -2147,6 +2175,8 @@ export interface Page {* This method drags the source element to the target element. It will first move to the source element, perform a* `mousedown`, then move to the target element and perform a `mouseup`.*+ * **Usage**+ ** ```js* await page.dragAndDrop('#source', '#target');* // or specify exact positions relative to the top-left corners of the elements:@@ -2218,6 +2248,8 @@ export interface Page {* This method changes the `CSS media type` through the `media` argument, and/or the `'prefers-colors-scheme'` media* feature, using the `colorScheme` argument.*+ * **Usage**+ ** ```js* await page.evaluate(() => matchMedia('screen').matches);* // → true@@ -2289,6 +2321,8 @@ export interface Page {* [page.exposeFunction(name, callback)](https://playwright.dev/docs/api/class-page#page-expose-function) survive* navigations.*+ * **Usage**+ ** An example of adding a `sha256` function to the page:** ```js@@ -2392,6 +2426,8 @@ export interface Page {/*** Returns frame matching the specified criteria. Either `name` or `url` must be specified.*+ * **Usage**+ ** ```js* const frame = page.frame('frame-name');* ```@@ -2416,8 +2452,12 @@ export interface Page {/*** When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements- * in that iframe. Following snippet locates element with text "Submit" in the iframe with id `my-frame`, like- * `<iframe id="my-frame">`:+ * in that iframe.+ *+ * **Usage**+ *+ * Following snippet locates element with text "Submit" in the iframe with id `my-frame`, like `<iframe+ * id="my-frame">`:** ```js* const locator = page.frameLocator('#my-iframe').getByText('Submit');@@ -3121,6 +3161,8 @@ export interface Page {* [`-webkit-print-color-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust)* property to force rendering of exact colors.*+ * **Usage**+ ** ```js* // Generates a PDF with 'screen' media type.* await page.emulateMedia({media: 'screen'});@@ -3277,6 +3319,8 @@ export interface Page {* Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the* modifier, modifier is pressed and being held while the subsequent key is being pressed.*+ * **Usage**+ ** ```js* const page = await browser.newPage();* await page.goto('https://keycode.info');@@ -3371,6 +3415,8 @@ export interface Page {* issue. We recommend disabling Service Workers when using request interception by setting* `Browser.newContext.serviceWorkers` to `'block'`.*+ * **Usage**+ ** An example of a naive handler that aborts all image requests:** ```js@@ -3473,6 +3519,8 @@ export interface Page {** Triggers a `change` and `input` event once all the provided options have been selected.*+ * **Usage**+ ** ```js* // single selection matching the value* page.selectOption('select#colors', 'blue');@@ -3762,6 +3810,8 @@ export interface Page {* [browser.newContext([options])](https://playwright.dev/docs/api/class-browser#browser-new-context) with `screen`* and `viewport` parameters if you need better control of these properties.*+ * **Usage**+ ** ```js* const page = await browser.newPage();* await page.setViewportSize({@@ -3892,6 +3942,8 @@ export interface Page {* To press a special key, like `Control` or `ArrowDown`, use* [keyboard.press(key[, options])](https://playwright.dev/docs/api/class-keyboard#keyboard-press).*+ * **Usage**+ ** ```js* await page.type('#mytextarea', 'Hello'); // Types instantly* await page.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user@@ -4237,6 +4289,8 @@ export interface Page {* committed when this method is called. If current document has already reached the required state, resolves* immediately.*+ * **Usage**+ ** ```js* await page.getByRole('button').click(); // Click triggers navigation.* await page.waitForLoadState(); // The promise resolves after 'load' event.@@ -4278,6 +4332,8 @@ export interface Page {* navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or* navigation due to History API usage, the navigation will resolve with `null`.*+ * **Usage**+ ** This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will* indirectly cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from* a `setTimeout`. Consider this example:@@ -4334,6 +4390,8 @@ export interface Page {* Waits for the matching request and returns it. See [waiting for event](https://playwright.dev/docs/events#waiting-for-event) for more* details about events.*+ * **Usage**+ ** ```js* // Note that Promise.all prevents a race condition* // between clicking and waiting for the request.@@ -4369,6 +4427,8 @@ export interface Page {* Returns the matched response. See [waiting for event](https://playwright.dev/docs/events#waiting-for-event) for more details about* events.*+ * **Usage**+ ** ```js* // Note that Promise.all prevents a race condition* // between clicking and waiting for the response.@@ -4408,6 +4468,8 @@ export interface Page {* Note that `page.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going* to be flaky. Use signals such as network events, selectors becoming visible and others instead.*+ * **Usage**+ ** ```js* // wait for 1 second* await page.waitForTimeout(1000);@@ -4422,6 +4484,8 @@ export interface Page {/*** Waits for the main frame to navigate to the given URL.*+ * **Usage**+ ** ```js* await page.click('a.delayed-navigation'); // Clicking the link will indirectly cause a navigation* await page.waitForURL('**\/target.html');@@ -4515,6 +4579,8 @@ export interface Frame {* `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`:* `-0`, `NaN`, `Infinity`, `-Infinity`.*+ * **Usage**+ ** ```js* const result = await frame.evaluate(([x, y]) => {* return Promise.resolve(x * y);@@ -4556,6 +4622,8 @@ export interface Frame {* `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`:* `-0`, `NaN`, `Infinity`, `-Infinity`.*+ * **Usage**+ ** ```js* const result = await frame.evaluate(([x, y]) => {* return Promise.resolve(x * y);@@ -4598,6 +4666,8 @@ export interface Frame {* [frame.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-evaluate-handle)* would wait for the promise to resolve and return its value.*+ * **Usage**+ ** ```js* const aWindowHandle = await frame.evaluateHandle(() => Promise.resolve(window));* aWindowHandle; // Handle for the window object.@@ -4638,6 +4708,8 @@ export interface Frame {* [frame.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-evaluate-handle)* would wait for the promise to resolve and return its value.*+ * **Usage**+ ** ```js* const aWindowHandle = await frame.evaluateHandle(() => Promise.resolve(window));* aWindowHandle; // Handle for the window object.@@ -4724,7 +4796,7 @@ export interface Frame {* [frame.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const searchValue = await frame.$eval('#search', el => el.value);@@ -4754,7 +4826,7 @@ export interface Frame {* [frame.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const searchValue = await frame.$eval('#search', el => el.value);@@ -4784,7 +4856,7 @@ export interface Frame {* [frame.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const searchValue = await frame.$eval('#search', el => el.value);@@ -4814,7 +4886,7 @@ export interface Frame {* [frame.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const searchValue = await frame.$eval('#search', el => el.value);@@ -4843,7 +4915,7 @@ export interface Frame {* [frame.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const divsCounts = await frame.$$eval('div', (divs, min) => divs.length >= min, 10);@@ -4868,7 +4940,7 @@ export interface Frame {* [frame.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const divsCounts = await frame.$$eval('div', (divs, min) => divs.length >= min, 10);@@ -4893,7 +4965,7 @@ export interface Frame {* [frame.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const divsCounts = await frame.$$eval('div', (divs, min) => divs.length >= min, 10);@@ -4918,7 +4990,7 @@ export interface Frame {* [frame.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const divsCounts = await frame.$$eval('div', (divs, min) => divs.length >= min, 10);@@ -4933,6 +5005,8 @@ export interface Frame {/*** Returns when the `pageFunction` returns a truthy value, returns that value.*+ * **Usage**+ ** The* [frame.waitForFunction(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-wait-for-function)* can be used to observe viewport size change:@@ -4965,6 +5039,8 @@ export interface Frame {/*** Returns when the `pageFunction` returns a truthy value, returns that value.*+ * **Usage**+ ** The* [frame.waitForFunction(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#frame-wait-for-function)* can be used to observe viewport size change:@@ -5006,6 +5082,8 @@ export interface Frame {* at the moment of calling the method `selector` already satisfies the condition, the method will return immediately.* If the selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.*+ * **Usage**+ ** This method works across navigations:** ```js@@ -5038,6 +5116,8 @@ export interface Frame {* at the moment of calling the method `selector` already satisfies the condition, the method will return immediately.* If the selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.*+ * **Usage**+ ** This method works across navigations:** ```js@@ -5070,6 +5150,8 @@ export interface Frame {* at the moment of calling the method `selector` already satisfies the condition, the method will return immediately.* If the selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.*+ * **Usage**+ ** This method works across navigations:** ```js@@ -5102,6 +5184,8 @@ export interface Frame {* at the moment of calling the method `selector` already satisfies the condition, the method will return immediately.* If the selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.*+ * **Usage**+ ** This method works across navigations:** ```js@@ -5410,6 +5494,8 @@ export interface Frame {* `click` is dispatched. This is equivalent to calling* [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).*+ * **Usage**+ ** ```js* await frame.dispatchEvent('button#submit', 'click');* ```@@ -5589,6 +5675,8 @@ export interface Frame {** This method throws an error if the frame has been detached before `frameElement()` returns.*+ * **Usage**+ ** ```js* const frameElement = await frame.frameElement();* const contentFrame = await frameElement.contentFrame();@@ -5600,8 +5688,12 @@ export interface Frame {/*** When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements- * in that iframe. Following snippet locates element with text "Submit" in the iframe with id `my-frame`, like- * `<iframe id="my-frame">`:+ * in that iframe.+ *+ * **Usage**+ *+ * Following snippet locates element with text "Submit" in the iframe with id `my-frame`, like `<iframe+ * id="my-frame">`:** ```js* const locator = frame.frameLocator('#my-iframe').getByText('Submit');@@ -6281,6 +6373,8 @@ export interface Frame {** Triggers a `change` and `input` event once all the provided options have been selected.*+ * **Usage**+ ** ```js* // single selection matching the value* frame.selectOption('select#colors', 'blue');@@ -6611,6 +6705,8 @@ export interface Frame {* To press a special key, like `Control` or `ArrowDown`, use* [keyboard.press(key[, options])](https://playwright.dev/docs/api/class-keyboard#keyboard-press).*+ * **Usage**+ ** ```js* await frame.type('#mytextarea', 'Hello'); // Types instantly* await frame.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user@@ -6722,6 +6818,8 @@ export interface Frame {* committed when this method is called. If current document has already reached the required state, resolves* immediately.*+ * **Usage**+ ** ```js* await frame.click('button'); // Click triggers navigation.* await frame.waitForLoadState(); // Waits for 'load' state by default.@@ -6750,6 +6848,8 @@ export interface Frame {* navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or* navigation due to History API usage, the navigation will resolve with `null`.*+ * **Usage**+ ** This method waits for the frame to navigate to a new URL. It is useful for when you run code which will indirectly* cause the frame to navigate. Consider this example:*@@ -6806,6 +6906,8 @@ export interface Frame {/*** Waits for the frame to navigate to the given URL.*+ * **Usage**+ ** ```js* await frame.click('a.delayed-navigation'); // Clicking the link will indirectly cause a navigation* await frame.waitForURL('**\/target.html');@@ -6873,6 +6975,8 @@ export interface BrowserContext {* See [page.exposeBinding(name, callback[, options])](https://playwright.dev/docs/api/class-page#page-expose-binding)* for page-only version.*+ * **Usage**+ ** An example of exposing page URL to all frames in all pages in the context:** ```js@@ -6927,6 +7031,8 @@ export interface BrowserContext {* See [page.exposeBinding(name, callback[, options])](https://playwright.dev/docs/api/class-page#page-expose-binding)* for page-only version.*+ * **Usage**+ ** An example of exposing page URL to all frames in all pages in the context:** ```js@@ -6980,6 +7086,8 @@ export interface BrowserContext {* The script is evaluated after the document was created but before any of its scripts were run. This is useful to* amend the JavaScript environment, e.g. to seed `Math.random`.*+ * **Usage**+ ** An example of overriding `Math.random` before the page loads:** ```js@@ -7394,6 +7502,8 @@ export interface BrowserContext {* can be obtained via* [browserContext.cookies([urls])](https://playwright.dev/docs/api/class-browsercontext#browser-context-cookies).*+ * **Usage**+ ** ```js* await browserContext.addCookies([cookieObject1, cookieObject2]);* ```@@ -7461,6 +7571,8 @@ export interface BrowserContext {/*** Clears all permission overrides for the browser context.*+ * **Usage**+ ** ```js* const context = await browser.newContext();* await context.grantPermissions(['clipboard-read']);@@ -7494,6 +7606,8 @@ export interface BrowserContext {* See [page.exposeFunction(name, callback)](https://playwright.dev/docs/api/class-page#page-expose-function) for* page-only version.*+ * **Usage**+ ** An example of adding a `sha256` function to all pages in the context:** ```js@@ -7583,6 +7697,8 @@ export interface BrowserContext {* [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when* using request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.*+ * **Usage**+ ** An example of a naive handler that aborts all image requests:** ```js@@ -7723,6 +7839,8 @@ export interface BrowserContext {/*** Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable.*+ * **Usage**+ ** ```js* await browserContext.setGeolocation({latitude: 59.95, longitude: 30.31667});* ```@@ -8068,7 +8186,7 @@ export interface JSHandle<T = any> {* If `pageFunction` returns a [Promise], then `handle.evaluate` would wait for the promise to resolve and return its* value.*- * Examples:+ * **Usage**** ```js* const tweetHandle = await page.$('.tweet .retweets');@@ -8087,7 +8205,7 @@ export interface JSHandle<T = any> {* If `pageFunction` returns a [Promise], then `handle.evaluate` would wait for the promise to resolve and return its* value.*- * Examples:+ * **Usage**** ```js* const tweetHandle = await page.$('.tweet .retweets');@@ -8153,6 +8271,8 @@ export interface JSHandle<T = any> {/*** The method returns a map with **own property names** as keys and JSHandle instances for the property values.*+ * **Usage**+ ** ```js* const handle = await page.evaluateHandle(() => ({window, document}));* const properties = await handle.getProperties();@@ -8254,7 +8374,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* [elementHandle.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const tweetHandle = await page.$('.tweet');@@ -8278,7 +8398,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* [elementHandle.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const tweetHandle = await page.$('.tweet');@@ -8302,7 +8422,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* [elementHandle.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const tweetHandle = await page.$('.tweet');@@ -8326,7 +8446,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* [elementHandle.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const tweetHandle = await page.$('.tweet');@@ -8351,7 +8471,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* [elementHandle.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```html* <div class="feed">@@ -8381,7 +8501,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* [elementHandle.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```html* <div class="feed">@@ -8411,7 +8531,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* [elementHandle.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```html* <div class="feed">@@ -8441,7 +8561,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* [elementHandle.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```html* <div class="feed">@@ -8470,6 +8590,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* method will return immediately. If the selector doesn't satisfy the condition for the `timeout` milliseconds, the* function will throw.*+ * **Usage**+ ** ```js* await page.setContent(`<div><span></span></div>`);* const div = await page.$('div');@@ -8493,6 +8615,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* method will return immediately. If the selector doesn't satisfy the condition for the `timeout` milliseconds, the* function will throw.*+ * **Usage**+ ** ```js* await page.setContent(`<div><span></span></div>`);* const div = await page.$('div');@@ -8516,6 +8640,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* method will return immediately. If the selector doesn't satisfy the condition for the `timeout` milliseconds, the* function will throw.*+ * **Usage**+ ** ```js* await page.setContent(`<div><span></span></div>`);* const div = await page.$('div');@@ -8539,6 +8665,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* method will return immediately. If the selector doesn't satisfy the condition for the `timeout` milliseconds, the* function will throw.*+ * **Usage**+ ** ```js* await page.setContent(`<div><span></span></div>`);* const div = await page.$('div');@@ -8567,6 +8695,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the* following snippet should click the center of the element.*+ * **Usage**+ ** ```js* const box = await elementHandle.boundingBox();* await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);@@ -8804,6 +8934,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* `click` is dispatched. This is equivalent to calling* [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).*+ * **Usage**+ ** ```js* await elementHandle.dispatchEvent('click');* ```@@ -9156,6 +9288,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {** Triggers a `change` and `input` event once all the provided options have been selected.*+ * **Usage**+ ** ```js* // single selection matching the value* handle.selectOption('blue');@@ -9432,6 +9566,8 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {* To press a special key, like `Control` or `ArrowDown`, use* [elementHandle.press(key[, options])](https://playwright.dev/docs/api/class-elementhandle#element-handle-press).*+ * **Usage**+ ** ```js* await elementHandle.type('Hello'); // Types instantly* await elementHandle.type('World', {delay: 100}); // Types slower, like a user@@ -9570,7 +9706,7 @@ export interface Locator {* If `pageFunction` returns a [Promise], then `handle.evaluate` would wait for the promise to resolve and return its* value.*- * Examples:+ * **Usage**** ```js* const tweets = page.locator('.tweet .retweets');@@ -9592,7 +9728,7 @@ export interface Locator {* If `pageFunction` returns a [Promise], then `handle.evaluate` would wait for the promise to resolve and return its* value.*- * Examples:+ * **Usage**** ```js* const tweets = page.locator('.tweet .retweets');@@ -9614,7 +9750,7 @@ export interface Locator {* [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const elements = page.locator('div');@@ -9633,7 +9769,7 @@ export interface Locator {* [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all)* would wait for the promise to resolve and return its value.*- * Examples:+ * **Usage**** ```js* const elements = page.locator('div');@@ -9690,6 +9826,8 @@ export interface Locator {* Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the* following snippet should click the center of the element.*+ * **Usage**+ ** ```js* const box = await element.boundingBox();* await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);@@ -9968,6 +10106,8 @@ export interface Locator {* `click` is dispatched. This is equivalent to calling* [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).*+ * **Usage**+ ** ```js* await element.dispatchEvent('click');* ```@@ -10010,6 +10150,8 @@ export interface Locator {* This method drags the locator to another target locator or target position. It will first move to the source* element, perform a `mousedown`, then move to the target element or position and perform a `mouseup`.*+ * **Usage**+ ** ```js* const source = page.locator('#source');* const target = page.locator('#target');@@ -10153,6 +10295,8 @@ export interface Locator {* This method narrows existing locator according to the options, for example filters by text. It can be chained to* filter multiple times.*+ * **Usage**+ ** ```js* const rowLocator = page.locator('tr');* // ...@@ -10201,6 +10345,8 @@ export interface Locator {}): Promise<void>;/**+ * **Usage**+ ** When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements* in that iframe:*@@ -10773,6 +10919,8 @@ export interface Locator {** Triggers a `change` and `input` event once all the provided options have been selected.*+ * **Usage**+ ** ```js* // single selection matching the value* element.selectOption('blue');@@ -11058,6 +11206,8 @@ export interface Locator {* To press a special key, like `Control` or `ArrowDown`, use* [locator.press(key[, options])](https://playwright.dev/docs/api/class-locator#locator-press).*+ * **Usage**+ ** ```js* await element.type('Hello'); // Types instantly* await element.type('World', {delay: 100}); // Types slower, like a user@@ -11157,6 +11307,8 @@ export interface Locator {* If target element already satisfies the condition, the method returns immediately. Otherwise, waits for up to* `timeout` milliseconds until the condition is met.*+ * **Usage**+ ** ```js* const orderSent = page.locator('#order-sent');* await orderSent.waitFor();@@ -11211,6 +11363,8 @@ export interface BrowserType<Unused = {}> {** > NOTE: Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.*+ * **Usage**+ ** ```js* const browser = await playwright.chromium.connectOverCDP('http://localhost:9222');* const defaultContext = browser.contexts()[0];@@ -11233,6 +11387,8 @@ export interface BrowserType<Unused = {}> {** > NOTE: Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.*+ * **Usage**+ ** ```js* const browser = await playwright.chromium.connectOverCDP('http://localhost:9222');* const defaultContext = browser.contexts()[0];@@ -11273,6 +11429,8 @@ export interface BrowserType<Unused = {}> {/*** Returns the browser instance.*+ * **Usage**+ ** You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments:** ```js@@ -11712,6 +11870,8 @@ export interface BrowserType<Unused = {}> {* [browserType.connect(wsEndpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect),* which requires the major/minor client/server version to match (1.2.3 → is compatible with 1.2.x).*+ * **Usage**+ ** Launches browser server that client can connect to. An example of launching a browser executable and connecting to* it later:*@@ -11987,6 +12147,8 @@ export interface Accessibility {* > NOTE: The Chromium accessibility tree contains nodes that go unused on most platforms and by most screen readers.* Playwright will discard them as well for an easier to process tree, unless `interestingOnly` is set to `false`.*+ * **Usage**+ ** An example of dumping the entire accessibility tree:** ```js@@ -12249,7 +12411,9 @@ export interface ElectronApplication {context(): BrowserContext;/**- * Convenience method that waits for the first application window to be opened. Typically your script will start with:+ * Convenience method that waits for the first application window to be opened.+ *+ * **Usage**** ```js* const electronApp = await electron.launch({@@ -12510,6 +12674,8 @@ export interface Android {/*** Launches Playwright Android server that clients can connect to. See the following example:*+ * **Usage**+ ** Server Side:** ```js@@ -13723,9 +13889,10 @@ export interface APIRequestContext {/*** Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and- * update context cookies from the response. The method will automatically follow redirects.+ * update context cookies from the response. The method will automatically follow redirects. JSON objects can be+ * passed directly to the request.*- * JSON objects can be passed directly to the request:+ * **Usage**** ```js* await request.fetch('https://example.com/api/createBook', {@@ -13849,6 +14016,8 @@ export interface APIRequestContext {* response. The method will populate request cookies from the context and update context cookies from the response.* The method will automatically follow redirects.*+ * **Usage**+ ** Request parameters can be configured with `params` option, they will be serialized into the URL search parameters:** ```js@@ -14098,6 +14267,8 @@ export interface APIRequestContext {* response. The method will populate request cookies from the context and update context cookies from the response.* The method will automatically follow redirects.*+ * **Usage**+ ** JSON objects can be passed directly to the request:** ```js@@ -14500,6 +14671,8 @@ export interface Browser extends EventEmitter {/*** Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.*+ * **Usage**+ ** ```js* const browser = await pw.webkit.launch();* console.log(browser.contexts().length); // prints `0`@@ -14533,6 +14706,8 @@ export interface Browser extends EventEmitter {* [browser.close()](https://playwright.dev/docs/api/class-browser#browser-close). This will ensure the `context` is* closed gracefully and any artifacts—like HARs and videos—are fully flushed and saved.*+ * **Usage**+ ** ```js* (async () => {* const browser = await playwright.firefox.launch(); // Or 'chromium' or 'webkit'.@@ -14939,6 +15114,8 @@ export interface Browser extends EventEmitter {* [browser.stopTracing()](https://playwright.dev/docs/api/class-browser#browser-stop-tracing) to create a trace file* that can be opened in Chrome DevTools performance panel.*+ * **Usage**+ ** ```js* await browser.startTracing(page, {path: 'trace.json'});* await page.goto('https://www.google.com');@@ -16073,6 +16250,8 @@ export interface Keyboard {/*** Dispatches only `input` event, does not emit the `keydown`, `keyup` or `keypress` events.*+ * **Usage**+ ** ```js* page.keyboard.insertText('嗨');* ```@@ -16103,6 +16282,8 @@ export interface Keyboard {* Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the* modifier, modifier is pressed and being held while the subsequent key is being pressed.*+ * **Usage**+ ** ```js* const page = await browser.newPage();* await page.goto('https://keycode.info');@@ -16133,6 +16314,8 @@ export interface Keyboard {* To press a special key, like `Control` or `ArrowDown`, use* [keyboard.press(key[, options])](https://playwright.dev/docs/api/class-keyboard#keyboard-press).*+ * **Usage**+ ** ```js* await page.keyboard.type('Hello'); // Types instantly* await page.keyboard.type('World', {delay: 100}); // Types slower, like a user@@ -16373,6 +16556,8 @@ export interface Request {/*** The method returns `null` unless this request has failed, as reported by `requestfailed` event.*+ * **Usage**+ ** Example of logging of all the failed requests:** ```js@@ -16460,6 +16645,8 @@ export interface Request {* by `redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible to* construct the whole redirect chain by repeatedly calling `redirectedFrom()`.*+ * **Usage**+ ** For example, if the website `http://example.com` redirects to `https://example.com`:** ```js@@ -16480,6 +16667,8 @@ export interface Request {/*** New request issued by the browser if the server responded with redirect.*+ * **Usage**+ ** This method is the opposite of* [request.redirectedFrom()](https://playwright.dev/docs/api/class-request#request-redirected-from):*@@ -16541,6 +16730,8 @@ export interface Request {* response, `responseEnd` becomes available when request finishes. Find more information at* [Resource Timing API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming).*+ * **Usage**+ ** ```js* const [request] = await Promise.all([* page.waitForEvent('requestfinished'),@@ -16796,6 +16987,8 @@ export interface Route {/*** Continues route's request with optional overrides.*+ * **Usage**+ ** ```js* await page.route('**\/*', (route, request) => {* // Override headers@@ -16838,6 +17031,8 @@ export interface Route {* the bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first* registered route.*+ * **Usage**+ ** ```js* await page.route('**\/*', route => {* // Runs last.@@ -16921,6 +17116,8 @@ export interface Route {/*** Fulfills route's request with given response.*+ * **Usage**+ ** An example of fulfilling all requests with 404 responses:** ```js@@ -16987,6 +17184,8 @@ export interface Route {*/export interface Selectors {/**+ * **Usage**+ ** An example of registering selector engine that queries elements based on a tag name:** ```js@@ -17090,6 +17289,8 @@ export interface Tracing {/*** Start tracing.*+ * **Usage**+ ** ```js* await context.tracing.start({ screenshots: true, snapshots: true });* const page = await context.newPage();@@ -17137,6 +17338,8 @@ export interface Tracing {* [tracing.startChunk([options])](https://playwright.dev/docs/api/class-tracing#tracing-start-chunk) and* [tracing.stopChunk([options])](https://playwright.dev/docs/api/class-tracing#tracing-stop-chunk).*+ * **Usage**+ ** ```js* await context.tracing.start({ screenshots: true, snapshots: true });* const page = await context.newPage();diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.tsindex a23101d428..deef84c90e 100644--- a/packages/playwright-test/types/test.d.ts+++ b/packages/playwright-test/types/test.d.ts@@ -3387,6 +3387,8 @@ interface APIResponseAssertions {/*** Ensures the response status code is within `200..299` range.*+ * **Usage**+ ** ```js* await expect(response).toBeOK();* ```@@ -3426,6 +3428,8 @@ interface LocatorAssertions {/*** Ensures the [Locator] points to a checked input.*+ * **Usage**+ ** ```js* const locator = page.getByLabel('Subscribe to newsletter');* await expect(locator).toBeChecked();@@ -3449,6 +3453,8 @@ interface LocatorAssertions {* that only native control elements such as HTML `button`, `input`, `select`, `textarea`, `option`, `optgroup` can be* disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored by the browser.*+ * **Usage**+ ** ```js* const locator = page.locator('button.submit');* await expect(locator).toBeDisabled();@@ -3466,6 +3472,8 @@ interface LocatorAssertions {/*** Ensures the [Locator] points to an editable element.*+ * **Usage**+ ** ```js* const locator = page.getByRole('textbox');* await expect(locator).toBeEditable();@@ -3485,6 +3493,8 @@ interface LocatorAssertions {/*** Ensures the [Locator] points to an empty editable element or to a DOM node that has no text.*+ * **Usage**+ ** ```js* const locator = page.locator('div.warning');* await expect(locator).toBeEmpty();@@ -3502,6 +3512,8 @@ interface LocatorAssertions {/*** Ensures the [Locator] points to an enabled element.*+ * **Usage**+ ** ```js* const locator = page.locator('button.submit');* await expect(locator).toBeEnabled();@@ -3521,6 +3533,8 @@ interface LocatorAssertions {/*** Ensures the [Locator] points to a focused DOM node.*+ * **Usage**+ ** ```js* const locator = page.getByRole('textbox');* await expect(locator).toBeFocused();@@ -3539,6 +3553,8 @@ interface LocatorAssertions {* Ensures that [Locator] either does not resolve to any DOM node, or resolves to a* [non-visible](https://playwright.dev/docs/api/actionability#visible) one.*+ * **Usage**+ ** ```js* const locator = page.locator('.my-element');* await expect(locator).toBeHidden();@@ -3557,6 +3573,8 @@ interface LocatorAssertions {* Ensures that [Locator] points to an [attached](https://playwright.dev/docs/api/actionability#attached) and* [visible](https://playwright.dev/docs/api/actionability#visible) DOM node.*+ * **Usage**+ ** ```js* const locator = page.locator('.my-element');* await expect(locator).toBeVisible();@@ -3577,6 +3595,8 @@ interface LocatorAssertions {* Ensures the [Locator] points to an element that contains the given text. You can use regular expressions for the* value as well.*+ * **Usage**+ ** ```js* const locator = page.locator('.title');* await expect(locator).toContainText('substring');@@ -3639,6 +3659,8 @@ interface LocatorAssertions {/*** Ensures the [Locator] points to an element with given attribute.*+ * **Usage**+ ** ```js* const locator = page.locator('input');* await expect(locator).toHaveAttribute('type', 'text');@@ -3659,6 +3681,8 @@ interface LocatorAssertions {* Ensures the [Locator] points to an element with given CSS classes. This needs to be a full match or using a relaxed* regular expression.*+ * **Usage**+ ** ```html* <div class='selected row' id='component'></div>* ```@@ -3689,6 +3713,8 @@ interface LocatorAssertions {/*** Ensures the [Locator] resolves to an exact number of DOM nodes.*+ * **Usage**+ ** ```js* const list = page.locator('list > .component');* await expect(list).toHaveCount(3);@@ -3707,6 +3733,8 @@ interface LocatorAssertions {/*** Ensures the [Locator] resolves to an element with the given computed CSS style.*+ * **Usage**+ ** ```js* const locator = page.getByRole('button');* await expect(locator).toHaveCSS('display', 'flex');@@ -3726,6 +3754,8 @@ interface LocatorAssertions {/*** Ensures the [Locator] points to an element with the given DOM Node ID.*+ * **Usage**+ ** ```js* const locator = page.getByRole('textbox');* await expect(locator).toHaveId('lastname');@@ -3745,6 +3775,8 @@ interface LocatorAssertions {* Ensures the [Locator] points to an element with given JavaScript property. Note that this property can be of a* primitive type as well as a plain serializable JavaScript object.*+ * **Usage**+ ** ```js* const locator = page.locator('.component');* await expect(locator).toHaveJSProperty('loaded', true);@@ -3765,6 +3797,8 @@ interface LocatorAssertions {* This function will wait until two consecutive locator screenshots yield the same result, and then compare the last* screenshot with the expectation.*+ * **Usage**+ ** ```js* const locator = page.getByRole('button');* await expect(locator).toHaveScreenshot('image.png');@@ -3840,6 +3874,8 @@ interface LocatorAssertions {* This function will wait until two consecutive locator screenshots yield the same result, and then compare the last* screenshot with the expectation.*+ * **Usage**+ ** ```js* const locator = page.getByRole('button');* await expect(locator).toHaveScreenshot();@@ -3914,6 +3950,8 @@ interface LocatorAssertions {* Ensures the [Locator] points to an element with the given text. You can use regular expressions for the value as* well.*+ * **Usage**+ ** ```js* const locator = page.locator('.title');* await expect(locator).toHaveText(/Welcome, Test User/);@@ -3976,6 +4014,8 @@ interface LocatorAssertions {* Ensures the [Locator] points to an element with the given input value. You can use regular expressions for the* value as well.*+ * **Usage**+ ** ```js* const locator = page.locator('input[type=number]');* await expect(locator).toHaveValue(/[0-9]/);@@ -3995,6 +4035,8 @@ interface LocatorAssertions {* Ensures the [Locator] points to multi-select/combobox (i.e. a `select` with the `multiple` attribute) and the* specified values are selected.*+ * **Usage**+ ** For example, given the following element:** ```html@@ -4054,6 +4096,8 @@ interface PageAssertions {* This function will wait until two consecutive page screenshots yield the same result, and then compare the last* screenshot with the expectation.*+ * **Usage**+ ** ```js* await expect(page).toHaveScreenshot('image.png');* ```@@ -4159,6 +4203,8 @@ interface PageAssertions {* This function will wait until two consecutive page screenshots yield the same result, and then compare the last* screenshot with the expectation.*+ * **Usage**+ ** ```js* await expect(page).toHaveScreenshot();* ```@@ -4262,6 +4308,8 @@ interface PageAssertions {/*** Ensures the page has the given title.*+ * **Usage**+ ** ```js* await expect(page).toHaveTitle(/.*checkout/);* ```@@ -4279,6 +4327,8 @@ interface PageAssertions {/*** Ensures the page is navigated to the given URL.*+ * **Usage**+ ** ```js* await expect(page).toHaveURL(/.*checkout/);* ```@@ -4307,6 +4357,8 @@ interface ScreenshotAssertions {* Ensures that passed value, either a [string] or a [Buffer], matches the expected snapshot stored in the test* snapshots directory.*+ * **Usage**+ ** ```js* // Basic usage.* expect(await page.screenshot()).toMatchSnapshot('landing-page.png');@@ -4353,6 +4405,8 @@ interface ScreenshotAssertions {* Ensures that passed value, either a [string] or a [Buffer], matches the expected snapshot stored in the test* snapshots directory.*+ * **Usage**+ ** ```js* // Basic usage and the file name is derived from the test name.* expect(await page.screenshot()).toMatchSnapshot();