From 94321fef1c94f9851b6fcc4304d3844760e986cb Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Tue, 15 Oct 2024 18:47:26 -0700 Subject: [PATCH] chore: implement locator.ariaSnapshot (#33125) --- docs/src/api/class-locator.md | 57 +++++++++++++++++++ .../playwright-core/src/client/locator.ts | 5 ++ .../playwright-core/src/protocol/validator.ts | 7 +++ .../src/server/dispatchers/frameDispatcher.ts | 4 ++ packages/playwright-core/src/server/dom.ts | 4 ++ packages/playwright-core/src/server/frames.ts | 7 +++ .../src/server/injected/consoleApi.ts | 3 +- .../src/server/injected/injectedScript.ts | 6 +- .../src/server/injected/recorder/recorder.ts | 2 +- packages/playwright-core/types/types.d.ts | 51 +++++++++++++++++ packages/protocol/src/channels.ts | 11 ++++ packages/protocol/src/protocol.yml | 7 +++ tests/page/page-aria-snapshot.spec.ts | 40 +++++++++++++ 13 files changed, 199 insertions(+), 5 deletions(-) create mode 100644 tests/page/page-aria-snapshot.spec.ts diff --git a/docs/src/api/class-locator.md b/docs/src/api/class-locator.md index 8f0b53e16d..ba6dc91353 100644 --- a/docs/src/api/class-locator.md +++ b/docs/src/api/class-locator.md @@ -150,6 +150,63 @@ var button = page.GetByRole(AriaRole.Button).And(page.GetByTitle("Subscribe")); Additional locator to match. +## async method: Locator.ariaSnapshot +* since: v1.49 +- returns: <[string]> + +Captures the aria snapshot of the given element. See [`method: LocatorAssertions.toMatchAriaSnapshot`] for the corresponding assertion. + +**Usage** + +```js +await page.getByRole('link').ariaSnapshot(); +``` + +```java +page.getByRole(AriaRole.LINK).ariaSnapshot(); +``` + +```python async +await page.get_by_role("link").aria_snapshot() +``` + +```python sync +page.get_by_role("link").aria_snapshot() +``` + +```csharp +await page.GetByRole(AriaRole.Link).AriaSnapshotAsync(); +``` + +**Details** + +This method captures the aria snapshot of the given element. The snapshot is a string that represents the state of the element and its children. +The snapshot can be used to assert the state of the element in the test, or to compare it to state in the future. + +The ARIA snapshot is represented using [YAML](https://yaml.org/spec/1.2.2/) markup language: +* The keys of the objects are the roles and optional accessible names of the elements. +* The values are either text content or an array of child elements. +* Generic static text can be represented with the `text` key. + +Below is the HTML markup and the respective ARIA snapshot: + +```html +