diff --git a/dotnet/docs/api/class-locator.mdx b/dotnet/docs/api/class-locator.mdx index 3d9b5ac6f85..43f74b359f9 100644 --- a/dotnet/docs/api/class-locator.mdx +++ b/dotnet/docs/api/class-locator.mdx @@ -115,7 +115,7 @@ var button = page.GetByRole(AriaRole.Button).And(page.GetByTitle("Subscribe")); Added in: v1.49locator.AriaSnapshotAsync -Captures the aria snapshot of the given element. Read more about [aria snapshots](../aria-snapshots.mdx) and [Expect(Locator).ToMatchAriaSnapshotAsync()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-2) for the corresponding assertion. +Captures the aria snapshot of the given element. Read more about [aria snapshots](../aria-snapshots.mdx) and [Expect(Locator).ToMatchAriaSnapshotAsync()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-1) for the corresponding assertion. **Usage** diff --git a/dotnet/docs/api/class-locatorassertions.mdx b/dotnet/docs/api/class-locatorassertions.mdx index 55998f1ed6a..93d1146f771 100644 --- a/dotnet/docs/api/class-locatorassertions.mdx +++ b/dotnet/docs/api/class-locatorassertions.mdx @@ -499,21 +499,21 @@ await Expect(locator).ToHaveAttributeAsync("type", "text"); Added in: v1.20locatorAssertions.ToHaveClassAsync -Ensures the [Locator] points to an element with given CSS classes. This needs to be a full match or using a relaxed regular expression. +Ensures the [Locator] points to an element with given CSS classes. When a string is provided, it must fully match the element's `class` attribute. To match individual classes or perform partial matches, use a regular expression: **Usage** ```html -
+
``` ```csharp var locator = Page.Locator("#component"); -await Expect(locator).ToHaveClassAsync(new Regex("selected")); -await Expect(locator).ToHaveClassAsync("selected row"); +await Expect(locator).ToHaveClassAsync(new Regex("(^|\\s)selected(\\s|$)")); +await Expect(locator).ToHaveClassAsync("middle selected row"); ``` -Note that if array is passed as an expected value, entire lists of elements can be asserted: +When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected class values. Each element's class attribute is matched against the corresponding string or regular expression in the array: ```csharp var locator = Page.Locator("list > .component"); @@ -811,23 +811,25 @@ await Expect(locator).ToHaveValuesAsync(new Regex[] { new Regex("R"), new Regex( --- -### ToMatchAriaSnapshotAsync(options) {#locator-assertions-to-match-aria-snapshot-1} +### ToMatchAriaSnapshotAsync(expected, options) {#locator-assertions-to-match-aria-snapshot-1} -Added in: v1.50locatorAssertions.ToMatchAriaSnapshotAsync(options) +Added in: v1.49locatorAssertions.ToMatchAriaSnapshotAsync(expected, options) Asserts that the target element matches the given [accessibility snapshot](../aria-snapshots.mdx). **Usage** ```csharp -await Expect(page.Locator("body")).ToMatchAriaSnapshotAsync(new { Path = "/path/to/snapshot.yml" }); +await page.GotoAsync("https://demo.playwright.dev/todomvc/"); +await Expect(page.Locator("body")).ToMatchAriaSnapshotAsync(@" + - heading ""todos"" + - textbox ""What needs to be done?"" +"); ``` **Arguments** +- `expected` [string]# - `options` `LocatorAssertionsToMatchAriaSnapshotOptions?` *(optional)* - - `Path` [string]? *(optional)*# - - Path to the YAML snapshot file. - `Timeout` [float]? *(optional)*# Time to retry the assertion for in milliseconds. Defaults to `5000`. @@ -837,25 +839,23 @@ await Expect(page.Locator("body")).ToMatchAriaSnapshotAsync(new { Path = "/path/ --- -### ToMatchAriaSnapshotAsync(expected, options) {#locator-assertions-to-match-aria-snapshot-2} +### ToMatchAriaSnapshotAsync(options) {#locator-assertions-to-match-aria-snapshot-2} -Added in: v1.49locatorAssertions.ToMatchAriaSnapshotAsync(expected, options) +Added in: v1.50locatorAssertions.ToMatchAriaSnapshotAsync(options) Asserts that the target element matches the given [accessibility snapshot](../aria-snapshots.mdx). **Usage** ```csharp -await page.GotoAsync("https://demo.playwright.dev/todomvc/"); -await Expect(page.Locator("body")).ToMatchAriaSnapshotAsync(@" - - heading ""todos"" - - textbox ""What needs to be done?"" -"); +await Expect(page.Locator("body")).ToMatchAriaSnapshotAsync(new { Path = "/path/to/snapshot.yml" }); ``` **Arguments** -- `expected` [string]# - `options` `LocatorAssertionsToMatchAriaSnapshotOptions?` *(optional)* + - `Path` [string]? *(optional)*# + + Path to the YAML snapshot file. - `Timeout` [float]? *(optional)*# Time to retry the assertion for in milliseconds. Defaults to `5000`. diff --git a/dotnet/docs/aria-snapshots.mdx b/dotnet/docs/aria-snapshots.mdx index 467b7f573dd..db218e18d9e 100644 --- a/dotnet/docs/aria-snapshots.mdx +++ b/dotnet/docs/aria-snapshots.mdx @@ -88,7 +88,7 @@ These values are derived from ARIA attributes or calculated based on HTML semant ## Snapshot matching -The [Expect(Locator).ToMatchAriaSnapshotAsync()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-2) assertion method in Playwright compares the accessible structure of the locator scope with a predefined aria snapshot template, helping validate the page's state against testing requirements. +The [Expect(Locator).ToMatchAriaSnapshotAsync()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-1) assertion method in Playwright compares the accessible structure of the locator scope with a predefined aria snapshot template, helping validate the page's state against testing requirements. For the following DOM: diff --git a/dotnet/docs/release-notes.mdx b/dotnet/docs/release-notes.mdx index 178dcfac484..58459e24267 100644 --- a/dotnet/docs/release-notes.mdx +++ b/dotnet/docs/release-notes.mdx @@ -11,7 +11,7 @@ import HTMLCard from '@site/src/components/HTMLCard'; ### Aria snapshots -New assertion [Expect(Locator).ToMatchAriaSnapshotAsync()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-2) verifies page structure by comparing to an expected accessibility tree, represented as YAML. +New assertion [Expect(Locator).ToMatchAriaSnapshotAsync()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-1) verifies page structure by comparing to an expected accessibility tree, represented as YAML. ```csharp await page.GotoAsync("https://playwright.dev"); diff --git a/java/docs/api/class-locator.mdx b/java/docs/api/class-locator.mdx index 2895e2c1978..4c0842f9884 100644 --- a/java/docs/api/class-locator.mdx +++ b/java/docs/api/class-locator.mdx @@ -115,7 +115,7 @@ Locator button = page.getByRole(AriaRole.BUTTON).and(page.getByTitle("Subscribe" Added in: v1.49locator.ariaSnapshot -Captures the aria snapshot of the given element. Read more about [aria snapshots](../aria-snapshots.mdx) and [assertThat(locator).matchesAriaSnapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-2) for the corresponding assertion. +Captures the aria snapshot of the given element. Read more about [aria snapshots](../aria-snapshots.mdx) and [assertThat(locator).matchesAriaSnapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-1) for the corresponding assertion. **Usage** diff --git a/java/docs/api/class-locatorassertions.mdx b/java/docs/api/class-locatorassertions.mdx index fc43eee22f5..d228f52a67e 100644 --- a/java/docs/api/class-locatorassertions.mdx +++ b/java/docs/api/class-locatorassertions.mdx @@ -223,20 +223,20 @@ assertThat(page.locator("input")).hasAttribute("type", "text"); Added in: v1.20locatorAssertions.hasClass -Ensures the [Locator] points to an element with given CSS classes. This needs to be a full match or using a relaxed regular expression. +Ensures the [Locator] points to an element with given CSS classes. When a string is provided, it must fully match the element's `class` attribute. To match individual classes or perform partial matches, use a regular expression: **Usage** ```html -
+
``` ```java -assertThat(page.locator("#component")).hasClass(Pattern.compile("selected")); -assertThat(page.locator("#component")).hasClass("selected row"); +assertThat(page.locator("#component")).hasClass(Pattern.compile("(^|\\s)selected(\\s|$)")); +assertThat(page.locator("#component")).hasClass("middle selected row"); ``` -Note that if array is passed as an expected value, entire lists of elements can be asserted: +When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected class values. Each element's class attribute is matched against the corresponding string or regular expression in the array: ```java assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"}); @@ -788,23 +788,25 @@ assertThat( --- -### matchesAriaSnapshot(options) {#locator-assertions-to-match-aria-snapshot-1} +### matchesAriaSnapshot(expected) {#locator-assertions-to-match-aria-snapshot-1} -Added in: v1.50locatorAssertions.matchesAriaSnapshot(options) +Added in: v1.49locatorAssertions.matchesAriaSnapshot(expected) Asserts that the target element matches the given [accessibility snapshot](../aria-snapshots.mdx). **Usage** ```java -assertThat(page.locator("body")).matchesAriaSnapshot(new LocatorAssertions.MatchesAriaSnapshotOptions().setPath("/path/to/snapshot.yml")); +page.navigate("https://demo.playwright.dev/todomvc/"); +assertThat(page.locator("body")).matchesAriaSnapshot(""" + - heading "todos" + - textbox "What needs to be done?" +"""); ``` **Arguments** +- `expected` [String]# - `options` `LocatorAssertions.MatchesAriaSnapshotOptions` *(optional)* - - `setPath` [String] *(optional)*# - - Path to the YAML snapshot file. - `setTimeout` [double] *(optional)*# Time to retry the assertion for in milliseconds. Defaults to `5000`. @@ -814,25 +816,23 @@ assertThat(page.locator("body")).matchesAriaSnapshot(new LocatorAssertions.Match --- -### matchesAriaSnapshot(expected) {#locator-assertions-to-match-aria-snapshot-2} +### matchesAriaSnapshot(options) {#locator-assertions-to-match-aria-snapshot-2} -Added in: v1.49locatorAssertions.matchesAriaSnapshot(expected) +Added in: v1.50locatorAssertions.matchesAriaSnapshot(options) Asserts that the target element matches the given [accessibility snapshot](../aria-snapshots.mdx). **Usage** ```java -page.navigate("https://demo.playwright.dev/todomvc/"); -assertThat(page.locator("body")).matchesAriaSnapshot(""" - - heading "todos" - - textbox "What needs to be done?" -"""); +assertThat(page.locator("body")).matchesAriaSnapshot(new LocatorAssertions.MatchesAriaSnapshotOptions().setPath("/path/to/snapshot.yml")); ``` **Arguments** -- `expected` [String]# - `options` `LocatorAssertions.MatchesAriaSnapshotOptions` *(optional)* + - `setPath` [String] *(optional)*# + + Path to the YAML snapshot file. - `setTimeout` [double] *(optional)*# Time to retry the assertion for in milliseconds. Defaults to `5000`. diff --git a/java/docs/aria-snapshots.mdx b/java/docs/aria-snapshots.mdx index df1abb5d470..78eba4ad041 100644 --- a/java/docs/aria-snapshots.mdx +++ b/java/docs/aria-snapshots.mdx @@ -88,7 +88,7 @@ These values are derived from ARIA attributes or calculated based on HTML semant ## Snapshot matching -The [assertThat(locator).matchesAriaSnapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-2) assertion method in Playwright compares the accessible structure of the locator scope with a predefined aria snapshot template, helping validate the page's state against testing requirements. +The [assertThat(locator).matchesAriaSnapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-1) assertion method in Playwright compares the accessible structure of the locator scope with a predefined aria snapshot template, helping validate the page's state against testing requirements. For the following DOM: diff --git a/java/docs/release-notes.mdx b/java/docs/release-notes.mdx index 7ddd95a9d9b..a081b7480f9 100644 --- a/java/docs/release-notes.mdx +++ b/java/docs/release-notes.mdx @@ -11,7 +11,7 @@ import HTMLCard from '@site/src/components/HTMLCard'; ### Aria snapshots -New assertion [assertThat(locator).matchesAriaSnapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-2) verifies page structure by comparing to an expected accessibility tree, represented as YAML. +New assertion [assertThat(locator).matchesAriaSnapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-1) verifies page structure by comparing to an expected accessibility tree, represented as YAML. ```java page.navigate("https://playwright.dev"); diff --git a/nodejs/docs/api/class-locator.mdx b/nodejs/docs/api/class-locator.mdx index 3f71be7aed1..6aeaafbebf6 100644 --- a/nodejs/docs/api/class-locator.mdx +++ b/nodejs/docs/api/class-locator.mdx @@ -115,7 +115,7 @@ const button = page.getByRole('button').and(page.getByTitle('Subscribe')); Added in: v1.49locator.ariaSnapshot -Captures the aria snapshot of the given element. Read more about [aria snapshots](../aria-snapshots.mdx) and [expect(locator).toMatchAriaSnapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-2) for the corresponding assertion. +Captures the aria snapshot of the given element. Read more about [aria snapshots](../aria-snapshots.mdx) and [expect(locator).toMatchAriaSnapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-1) for the corresponding assertion. **Usage** diff --git a/nodejs/docs/api/class-locatorassertions.mdx b/nodejs/docs/api/class-locatorassertions.mdx index 671fd8e1523..a03d6fc630c 100644 --- a/nodejs/docs/api/class-locatorassertions.mdx +++ b/nodejs/docs/api/class-locatorassertions.mdx @@ -524,21 +524,21 @@ await expect(locator).toHaveAttribute(name, options); Added in: v1.20locatorAssertions.toHaveClass -Ensures the [Locator] points to an element with given CSS classes. This needs to be a full match or using a relaxed regular expression. +Ensures the [Locator] points to an element with given CSS classes. When a string is provided, it must fully match the element's `class` attribute. To match individual classes or perform partial matches, use a regular expression: **Usage** ```html -
+
``` ```js const locator = page.locator('#component'); -await expect(locator).toHaveClass(/selected/); -await expect(locator).toHaveClass('selected row'); +await expect(locator).toHaveClass('middle selected row'); +await expect(locator).toHaveClass(/(^|\s)selected(\s|$)/); ``` -Note that if array is passed as an expected value, entire lists of elements can be asserted: +When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected class values. Each element's class attribute is matched against the corresponding string or regular expression in the array: ```js const locator = page.locator('list > .component'); @@ -963,28 +963,25 @@ await expect(locator).toHaveValues([/R/, /G/]); --- -### toMatchAriaSnapshot(options) {#locator-assertions-to-match-aria-snapshot-1} +### toMatchAriaSnapshot(expected) {#locator-assertions-to-match-aria-snapshot-1} -Added in: v1.50locatorAssertions.toMatchAriaSnapshot(options) +Added in: v1.49locatorAssertions.toMatchAriaSnapshot(expected) Asserts that the target element matches the given [accessibility snapshot](../aria-snapshots.mdx). **Usage** ```js -await expect(page.locator('body')).toMatchAriaSnapshot(); -await expect(page.locator('body')).toMatchAriaSnapshot({ name: 'snapshot' }); -await expect(page.locator('body')).toMatchAriaSnapshot({ path: '/path/to/snapshot.yml' }); +await page.goto('https://demo.playwright.dev/todomvc/'); +await expect(page.locator('body')).toMatchAriaSnapshot(` + - heading "todos" + - textbox "What needs to be done?" +`); ``` **Arguments** +- `expected` [string]# - `options` [Object] *(optional)* - - `name` [string] *(optional)*# - - Name of the snapshot to store in the snapshot folder corresponding to this test. Generates ordinal name if not specified. - - `path` [string] *(optional)*# - - Path to the YAML snapshot file. - `timeout` [number] *(optional)*# Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`. @@ -994,25 +991,28 @@ await expect(page.locator('body')).toMatchAriaSnapshot({ path: '/path/to/snapsho --- -### toMatchAriaSnapshot(expected) {#locator-assertions-to-match-aria-snapshot-2} +### toMatchAriaSnapshot(options) {#locator-assertions-to-match-aria-snapshot-2} -Added in: v1.49locatorAssertions.toMatchAriaSnapshot(expected) +Added in: v1.50locatorAssertions.toMatchAriaSnapshot(options) Asserts that the target element matches the given [accessibility snapshot](../aria-snapshots.mdx). **Usage** ```js -await page.goto('https://demo.playwright.dev/todomvc/'); -await expect(page.locator('body')).toMatchAriaSnapshot(` - - heading "todos" - - textbox "What needs to be done?" -`); +await expect(page.locator('body')).toMatchAriaSnapshot(); +await expect(page.locator('body')).toMatchAriaSnapshot({ name: 'snapshot' }); +await expect(page.locator('body')).toMatchAriaSnapshot({ path: '/path/to/snapshot.yml' }); ``` **Arguments** -- `expected` [string]# - `options` [Object] *(optional)* + - `name` [string] *(optional)*# + + Name of the snapshot to store in the snapshot folder corresponding to this test. Generates ordinal name if not specified. + - `path` [string] *(optional)*# + + Path to the YAML snapshot file. - `timeout` [number] *(optional)*# Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`. diff --git a/nodejs/docs/api/class-test.mdx b/nodejs/docs/api/class-test.mdx index cf49191c0f6..0c300a0c8b0 100644 --- a/nodejs/docs/api/class-test.mdx +++ b/nodejs/docs/api/class-test.mdx @@ -1511,96 +1511,47 @@ test('example', async ({ page }) => { --- -### test.step.fail {#test-step-fail} +### test.step.skip {#test-step-skip} -Added in: v1.50test.test.step.fail +Added in: v1.50test.test.step.skip -Marks a test step as "should fail". Playwright runs this test step and ensures that it actually fails. This is useful for documentation purposes to acknowledge that some functionality is broken until it is fixed. - -:::note - -If the step exceeds the timeout, a [TimeoutError] is thrown. This indicates the step did not fail as expected. -::: - -**Usage** - -You can declare a test step as failing, so that Playwright ensures it actually fails. - -```js -import { test, expect } from '@playwright/test'; - -test('my test', async ({ page }) => { - // ... - await test.step.fail('currently failing', async () => { - // ... - }); -}); -``` - -**Arguments** -- `title` [string]# - - Step name. -- `body` [function]\(\):[Promise]<[Object]># - - Step body. -- `options` [Object] *(optional)* - - `box` [boolean] *(optional)*# - - Whether to box the step in the report. Defaults to `false`. When the step is boxed, errors thrown from the step internals point to the step call site. See below for more details. - - `location` [Location] *(optional)*# - - Specifies a custom location for the step to be shown in test reports and trace viewer. By default, location of the [test.step()](/api/class-test.mdx#test-step) call is shown. - - `timeout` [number] *(optional)*# - - Maximum time in milliseconds for the step to finish. Defaults to `0` (no timeout). - -**Returns** -- [Promise]<[void]># - ---- - -### test.step.fixme {#test-step-fixme} - -Added in: v1.50test.test.step.fixme - -Mark a test step as "fixme", with the intention to fix it. Playwright will not run the step. +Mark a test step as "skip" to temporarily disable its execution, useful for steps that are currently failing and planned for a near-term fix. Playwright will not run the step. **Usage** -You can declare a test step as failing, so that Playwright ensures it actually fails. +You can declare a skipped step, and Playwright will not run it. ```js import { test, expect } from '@playwright/test'; test('my test', async ({ page }) => { // ... - await test.step.fixme('not yet ready', async () => { + await test.step.skip('not yet ready', async () => { // ... }); }); ``` **Arguments** -- `title` [string]# +- `title` [string]# Step name. -- `body` [function]\(\):[Promise]<[Object]># +- `body` [function]\(\):[Promise]<[Object]># Step body. - `options` [Object] *(optional)* - - `box` [boolean] *(optional)*# + - `box` [boolean] *(optional)*# Whether to box the step in the report. Defaults to `false`. When the step is boxed, errors thrown from the step internals point to the step call site. See below for more details. - - `location` [Location] *(optional)*# + - `location` [Location] *(optional)*# Specifies a custom location for the step to be shown in test reports and trace viewer. By default, location of the [test.step()](/api/class-test.mdx#test-step) call is shown. - - `timeout` [number] *(optional)*# + - `timeout` [number] *(optional)*# Maximum time in milliseconds for the step to finish. Defaults to `0` (no timeout). **Returns** -- [Promise]<[void]># +- [Promise]<[void]># --- diff --git a/nodejs/docs/api/class-testconfig.mdx b/nodejs/docs/api/class-testconfig.mdx index b3a06186d97..bfaa69c7d81 100644 --- a/nodejs/docs/api/class-testconfig.mdx +++ b/nodejs/docs/api/class-testconfig.mdx @@ -861,10 +861,10 @@ export default defineConfig({ Added in: v1.50testConfig.updateSourceMethod -Defines how to update the source code snapshots. -* `'overwrite'` - Overwrite the source code snapshot with the actual result. -* `'3way'` - Use a three-way merge to update the source code snapshot. -* `'patch'` - Use a patch to update the source code snapshot. This is the default. +Defines how to update snapshots in the source code. +* `'patch'` - Create a unified diff file that can be used to update the source code later. This is the default. +* `'3way'` - Generate merge conflict markers in source code. This allows user to manually pick relevant changes, as if they are resolving a merge conflict in the IDE. +* `'overwrite'` - Overwrite the source code with the new snapshot values. **Usage** diff --git a/nodejs/docs/aria-snapshots.mdx b/nodejs/docs/aria-snapshots.mdx index b22815d8b5c..7753c44e48b 100644 --- a/nodejs/docs/aria-snapshots.mdx +++ b/nodejs/docs/aria-snapshots.mdx @@ -88,7 +88,7 @@ These values are derived from ARIA attributes or calculated based on HTML semant ## Snapshot matching -The [expect(locator).toMatchAriaSnapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-2) assertion method in Playwright compares the accessible structure of the locator scope with a predefined aria snapshot template, helping validate the page's state against testing requirements. +The [expect(locator).toMatchAriaSnapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-1) assertion method in Playwright compares the accessible structure of the locator scope with a predefined aria snapshot template, helping validate the page's state against testing requirements. For the following DOM: diff --git a/nodejs/docs/release-notes.mdx b/nodejs/docs/release-notes.mdx index ae0c6c8a541..628e12ab9c2 100644 --- a/nodejs/docs/release-notes.mdx +++ b/nodejs/docs/release-notes.mdx @@ -15,7 +15,7 @@ import LiteYouTube from '@site/src/components/LiteYouTube'; ### Aria snapshots -New assertion [expect(locator).toMatchAriaSnapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-2) verifies page structure by comparing to an expected accessibility tree, represented as YAML. +New assertion [expect(locator).toMatchAriaSnapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-1) verifies page structure by comparing to an expected accessibility tree, represented as YAML. ```js await page.goto('https://playwright.dev'); diff --git a/python/docs/api/class-locator.mdx b/python/docs/api/class-locator.mdx index f3173c6f302..4a323b4bed6 100644 --- a/python/docs/api/class-locator.mdx +++ b/python/docs/api/class-locator.mdx @@ -196,7 +196,7 @@ button = page.get_by_role("button").and_(page.getByTitle("Subscribe")) Added in: v1.49locator.aria_snapshot -Captures the aria snapshot of the given element. Read more about [aria snapshots](../aria-snapshots.mdx) and [expect(locator).to_match_aria_snapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-2) for the corresponding assertion. +Captures the aria snapshot of the given element. Read more about [aria snapshots](../aria-snapshots.mdx) and [expect(locator).to_match_aria_snapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-1) for the corresponding assertion. **Usage** diff --git a/python/docs/api/class-locatorassertions.mdx b/python/docs/api/class-locatorassertions.mdx index 51527c3141e..6b0125c3a6b 100644 --- a/python/docs/api/class-locatorassertions.mdx +++ b/python/docs/api/class-locatorassertions.mdx @@ -655,7 +655,7 @@ expect(locator).not_to_have_values(values, **kwargs) Added in: v1.49locatorAssertions.not_to_match_aria_snapshot -The opposite of [expect(locator).to_match_aria_snapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-2). +The opposite of [expect(locator).to_match_aria_snapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-1). **Usage** @@ -1532,12 +1532,12 @@ await expect(locator).to_have_attribute("type", "text") Added in: v1.20locatorAssertions.to_have_class -Ensures the [Locator] points to an element with given CSS classes. This needs to be a full match or using a relaxed regular expression. +Ensures the [Locator] points to an element with given CSS classes. When a string is provided, it must fully match the element's `class` attribute. To match individual classes or perform partial matches, use a regular expression: **Usage** ```html -
+
``` @@ -1565,14 +1565,14 @@ expect(locator).to_have_class("selected row") from playwright.async_api import expect locator = page.locator("#component") -await expect(locator).to_have_class(re.compile(r"selected")) -await expect(locator).to_have_class("selected row") +await expect(locator).to_have_class(re.compile(r"(^|\\s)selected(\\s|$)")) +await expect(locator).to_have_class("middle selected row") ``` -Note that if array is passed as an expected value, entire lists of elements can be asserted: +When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected class values. Each element's class attribute is matched against the corresponding string or regular expression in the array: Added in: v1.50locatorAssertions.to_match_aria_snapshot(**kwargs) +Added in: v1.49locatorAssertions.to_match_aria_snapshot(expected) Asserts that the target element matches the given [accessibility snapshot](../aria-snapshots.mdx). @@ -2143,23 +2143,29 @@ Asserts that the target element matches the given [accessibility snapshot](../ar ```py -expect(page.locator('body')).to_match_aria_snapshot(path='/path/to/snapshot.yml') +page.goto("https://demo.playwright.dev/todomvc/") +expect(page.locator('body')).to_match_aria_snapshot(''' + - heading "todos" + - textbox "What needs to be done?" +''') ``` ```py -await expect(page.locator('body')).to_match_aria_snapshot(path='/path/to/snapshot.yml') +await page.goto("https://demo.playwright.dev/todomvc/") +await expect(page.locator('body')).to_match_aria_snapshot(''' + - heading "todos" + - textbox "What needs to be done?" +''') ``` **Arguments** -- `path` [str] *(optional)*# - - Path to the YAML snapshot file. +- `expected` [str]# - `timeout` [float] *(optional)*# Time to retry the assertion for in milliseconds. Defaults to `5000`. @@ -2169,9 +2175,9 @@ await expect(page.locator('body')).to_match_aria_snapshot(path='/path/to/snapsho --- -### to_match_aria_snapshot(expected) {#locator-assertions-to-match-aria-snapshot-2} +### to_match_aria_snapshot(**kwargs) {#locator-assertions-to-match-aria-snapshot-2} -Added in: v1.49locatorAssertions.to_match_aria_snapshot(expected) +Added in: v1.50locatorAssertions.to_match_aria_snapshot(**kwargs) Asserts that the target element matches the given [accessibility snapshot](../aria-snapshots.mdx). @@ -2188,29 +2194,23 @@ Asserts that the target element matches the given [accessibility snapshot](../ar ```py -page.goto("https://demo.playwright.dev/todomvc/") -expect(page.locator('body')).to_match_aria_snapshot(''' - - heading "todos" - - textbox "What needs to be done?" -''') +expect(page.locator('body')).to_match_aria_snapshot(path='/path/to/snapshot.yml') ``` ```py -await page.goto("https://demo.playwright.dev/todomvc/") -await expect(page.locator('body')).to_match_aria_snapshot(''' - - heading "todos" - - textbox "What needs to be done?" -''') +await expect(page.locator('body')).to_match_aria_snapshot(path='/path/to/snapshot.yml') ``` **Arguments** -- `expected` [str]# +- `path` [str] *(optional)*# + + Path to the YAML snapshot file. - `timeout` [float] *(optional)*# Time to retry the assertion for in milliseconds. Defaults to `5000`. diff --git a/python/docs/aria-snapshots.mdx b/python/docs/aria-snapshots.mdx index af141df93c9..b8f73d0293b 100644 --- a/python/docs/aria-snapshots.mdx +++ b/python/docs/aria-snapshots.mdx @@ -115,7 +115,7 @@ These values are derived from ARIA attributes or calculated based on HTML semant ## Snapshot matching -The [expect(locator).to_match_aria_snapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-2) assertion method in Playwright compares the accessible structure of the locator scope with a predefined aria snapshot template, helping validate the page's state against testing requirements. +The [expect(locator).to_match_aria_snapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-1) assertion method in Playwright compares the accessible structure of the locator scope with a predefined aria snapshot template, helping validate the page's state against testing requirements. For the following DOM: diff --git a/python/docs/release-notes.mdx b/python/docs/release-notes.mdx index 8a9ce77dd3a..bb13197cc37 100644 --- a/python/docs/release-notes.mdx +++ b/python/docs/release-notes.mdx @@ -11,7 +11,7 @@ import HTMLCard from '@site/src/components/HTMLCard'; ### Aria snapshots -New assertion [expect(locator).to_match_aria_snapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-2) verifies page structure by comparing to an expected accessibility tree, represented as YAML. +New assertion [expect(locator).to_match_aria_snapshot()](/api/class-locatorassertions.mdx#locator-assertions-to-match-aria-snapshot-1) verifies page structure by comparing to an expected accessibility tree, represented as YAML. ```python page.goto("https://playwright.dev")