Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: delete page.accessibilitiy (#38152)

Yury Semikhatsky9d40b1ad20ad
diff --git a/docs/src/api/class-accessibility.md b/docs/src/api/class-accessibility.md
deleted file mode 100644
index e5efc9b21f..0000000000
--- a/docs/src/api/class-accessibility.md
+++ /dev/null
@@ -1,170 +0,0 @@
-# class: Accessibility
-* since: v1.8
-* langs: csharp, js, python
-* deprecated: This class is deprecated. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration with Axe.
-
-The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by
-assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or
-[switches](https://en.wikipedia.org/wiki/Switch_access).
-
-Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might
-have wildly different output.
-
-Rendering engines of Chromium, Firefox and WebKit have a concept of "accessibility tree", which is then translated into different
-platform-specific APIs. Accessibility namespace gives access to this Accessibility Tree.
-
-Most of the accessibility tree gets filtered out when converting from internal browser AX Tree to Platform-specific AX-Tree or by
-assistive technologies themselves. By default, Playwright tries to approximate this filtering, exposing only the
-"interesting" nodes of the tree.
-
-## async method: Accessibility.snapshot
-* since: v1.8
-* deprecated: This method is deprecated. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration with Axe.
-
-- returns: <[null]|[Object]>
- - `role` <[string]> The [role](https://www.w3.org/TR/wai-aria/#usage).
- - `name` <[string]> A human readable name for the node.
- - `value` <[string]|[float]> The current value of the node, if applicable.
- - `description` <[string]> An additional human readable description of the node, if applicable.
- - `keyshortcuts` <[string]> Keyboard shortcuts associated with this node, if applicable.
- - `roledescription` <[string]> A human readable alternative to the role, if applicable.
- - `valuetext` <[string]> A description of the current value, if applicable.
- - `disabled` <[boolean]> Whether the node is disabled, if applicable.
- - `expanded` <[boolean]> Whether the node is expanded or collapsed, if applicable.
- - `focused` <[boolean]> Whether the node is focused, if applicable.
- - `modal` <[boolean]> Whether the node is [modal](https://en.wikipedia.org/wiki/Modal_window), if applicable.
- - `multiline` <[boolean]> Whether the node text input supports multiline, if applicable.
- - `multiselectable` <[boolean]> Whether more than one child can be selected, if applicable.
- - `readonly` <[boolean]> Whether the node is read only, if applicable.
- - `required` <[boolean]> Whether the node is required, if applicable.
- - `selected` <[boolean]> Whether the node is selected in its parent node, if applicable.
- - `checked` <[boolean]|"mixed"> Whether the checkbox is checked, or "mixed", if applicable.
- - `pressed` <[boolean]|"mixed"> Whether the toggle button is checked, or "mixed", if applicable.
- - `level` <[int]> The level of a heading, if applicable.
- - `valuemin` <[float]> The minimum value in a node, if applicable.
- - `valuemax` <[float]> The maximum value in a node, if applicable.
- - `autocomplete` <[string]> What kind of autocomplete is supported by a control, if applicable.
- - `haspopup` <[string]> What kind of popup is currently being shown for a node, if applicable.
- - `invalid` <[string]> Whether and in what way this node's value is invalid, if applicable.
- - `orientation` <[string]> Whether the node is oriented horizontally or vertically, if applicable.
- - `children` <[Array]<[Object]>> Child nodes, if any, if applicable.
-
-Captures the current state of the accessibility tree. The returned object represents the root accessible node of the
-page.
-
-:::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 [`option: interestingOnly`] is set to `false`.
-:::
-
-**Usage**
-
-An example of dumping the entire accessibility tree:
-
-```js
-const snapshot = await page.accessibility.snapshot();
-console.log(snapshot);
-```
-
-```java
-String snapshot = page.accessibility().snapshot();
-System.out.println(snapshot);
-```
-
-```python async
-snapshot = await page.accessibility.snapshot()
-print(snapshot)
-```
-
-```python sync
-snapshot = page.accessibility.snapshot()
-print(snapshot)
-```
-
-```csharp
-var accessibilitySnapshot = await page.Accessibility.SnapshotAsync();
-Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(accessibilitySnapshot));
-```
-
-An example of logging the focused node's name:
-
-```js
-const snapshot = await page.accessibility.snapshot();
-const node = findFocusedNode(snapshot);
-console.log(node && node.name);
-
-function findFocusedNode(node) {
- if (node.focused)
- return node;
- for (const child of node.children || []) {
- const foundNode = findFocusedNode(child);
- if (foundNode)
- return foundNode;
- }
- return null;
-}
-```
-
-```csharp
-var accessibilitySnapshot = await page.Accessibility.SnapshotAsync();
-Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(accessibilitySnapshot));
-```
-
-```java
-// FIXME
-String snapshot = page.accessibility().snapshot();
-```
-
-```python async
-def find_focused_node(node):
- if node.get("focused"):
- return node
- for child in (node.get("children") or []):
- found_node = find_focused_node(child)
- if found_node:
- return found_node
- return None
-
-snapshot = await page.accessibility.snapshot()
-node = find_focused_node(snapshot)
-if node:
- print(node["name"])
-```
-
-```python sync
-def find_focused_node(node):
- if node.get("focused"):
- return node
- for child in (node.get("children") or []):
- found_node = find_focused_node(child)
- if found_node:
- return found_node
- return None
-
-snapshot = page.accessibility.snapshot()
-node = find_focused_node(snapshot)
-if node:
- print(node["name"])
-```
-
-## async method: Accessibility.snapshot
-* since: v1.8
-* langs: java
-- returns: <[null]|[string]>
-
-## async method: Accessibility.snapshot
-* since: v1.8
-* langs: csharp
-- returns: <[null]|[JsonElement]>
-
-### option: Accessibility.snapshot.interestingOnly
-* since: v1.8
-- `interestingOnly` <[boolean]>
-
-Prune uninteresting nodes from the tree. Defaults to `true`.
-
-### option: Accessibility.snapshot.root
-* since: v1.8
-- `root` <[ElementHandle]>
-
-The root DOM element for the snapshot. Defaults to the whole page.
diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md
index c45b55a32f..ad4a89bdab 100644
--- a/docs/src/api/class-page.md
+++ b/docs/src/api/class-page.md
@@ -557,13 +557,6 @@ Emitted when [WebSocket] request is sent.
Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned by the
page.
-## property: Page.accessibility
-* since: v1.8
-* langs: csharp, js, python
-* deprecated: This property is discouraged. Please use other libraries such as
- [Axe](https://www.deque.com/axe/) if you need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration with Axe.
-- type: <[Accessibility]>
-
## async method: Page.addInitScript
* since: v1.8
diff --git a/packages/playwright-client/types/types.d.ts b/packages/playwright-client/types/types.d.ts
index f360194364..d07ab6fc6c 100644
--- a/packages/playwright-client/types/types.d.ts
+++ b/packages/playwright-client/types/types.d.ts
@@ -5167,13 +5167,6 @@ export interface Page {
*/
workers(): Array<Worker>;
- /**
- * @deprecated This property is discouraged. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to
- * test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration
- * with Axe.
- */
- accessibility: Accessibility;
-
/**
* Playwright has ability to mock clock and passage of time.
*/
@@ -15772,97 +15765,6 @@ class TimeoutError extends Error {
}
-/**
- * The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is
- * used by assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or
- * [switches](https://en.wikipedia.org/wiki/Switch_access).
- *
- * Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that
- * might have wildly different output.
- *
- * Rendering engines of Chromium, Firefox and WebKit have a concept of "accessibility tree", which is then translated
- * into different platform-specific APIs. Accessibility namespace gives access to this Accessibility Tree.
- *
- * Most of the accessibility tree gets filtered out when converting from internal browser AX Tree to Platform-specific
- * AX-Tree or by assistive technologies themselves. By default, Playwright tries to approximate this filtering,
- * exposing only the "interesting" nodes of the tree.
- */
-export interface Accessibility {
- /**
- * Captures the current state of the accessibility tree. The returned object represents the root accessible node of
- * the page.
- *
- * **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`](https://playwright.dev/docs/api/class-accessibility#accessibility-snapshot-option-interesting-only)
- * is set to `false`.
- *
- * **Usage**
- *
- * An example of dumping the entire accessibility tree:
- *
- * ```js
- * const snapshot = await page.accessibility.snapshot();
- * console.log(snapshot);
- * ```
- *
- * An example of logging the focused node's name:
- *
- * ```js
- * const snapshot = await page.accessibility.snapshot();
- * const node = findFocusedNode(snapshot);
- * console.log(node && node.name);
- *
- * function findFocusedNode(node) {
- * if (node.focused)
- * return node;
- * for (const child of node.children || []) {
- * const foundNode = findFocusedNode(child);
- * if (foundNode)
- * return foundNode;
- * }
- * return null;
- * }
- * ```
- *
- * @deprecated This method is deprecated. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to test
- * page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration with
- * Axe.
- * @param options
- */
- snapshot(options?: AccessibilitySnapshotOptions): Promise<null|AccessibilityNode>;
-
-}
-
-type AccessibilityNode = {
- role: string;
- name: string;
- value?: string|number;
- description?: string;
- keyshortcuts?: string;
- roledescription?: string;
- valuetext?: string;
- disabled?: boolean;
- expanded?: boolean;
- focused?: boolean;
- modal?: boolean;
- multiline?: boolean;
- multiselectable?: boolean;
- readonly?: boolean;
- required?: boolean;
- selected?: boolean;
- checked?: boolean|"mixed";
- pressed?: boolean|"mixed";
- level?: number;
- valuemin?: number;
- valuemax?: number;
- autocomplete?: string;
- haspopup?: string;
- invalid?: string;
- orientation?: string;
- children?: AccessibilityNode[];
-}
-
export const devices: Devices;
//@ts-ignore this will be any if electron is not installed
@@ -21768,18 +21670,6 @@ export interface WebSocket {
}
-interface AccessibilitySnapshotOptions {
- /**
- * Prune uninteresting nodes from the tree. Defaults to `true`.
- */
- interestingOnly?: boolean;
-
- /**
- * The root DOM element for the snapshot. Defaults to the whole page.
- */
- root?: ElementHandle;
-}
-
export interface LaunchOptions {
/**
* **NOTE** Use custom browser args at your own risk, as some of them may break Playwright functionality.
diff --git a/packages/playwright-core/src/client/accessibility.ts b/packages/playwright-core/src/client/accessibility.ts
deleted file mode 100644
index 02db39e801..0000000000
--- a/packages/playwright-core/src/client/accessibility.ts
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Copyright 2017 Google Inc. All rights reserved.
- * Modifications copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import type { ElementHandle } from './elementHandle';
-import type * as api from '../../types/types';
-import type * as channels from '@protocol/channels';
-
-type SerializedAXNode = Omit<channels.AXNode, 'valueString' | 'valueNumber' | 'children' | 'checked' | 'pressed'> & {
- value?: string|number,
- checked?: boolean | 'mixed',
- pressed?: boolean | 'mixed',
- children?: SerializedAXNode[]
-};
-
-function axNodeFromProtocol(axNode: channels.AXNode): SerializedAXNode {
- const result: SerializedAXNode = {
- ...axNode,
- value: axNode.valueNumber !== undefined ? axNode.valueNumber : axNode.valueString,
- checked: axNode.checked === 'checked' ? true : axNode.checked === 'unchecked' ? false : axNode.checked,
- pressed: axNode.pressed === 'pressed' ? true : axNode.pressed === 'released' ? false : axNode.pressed,
- children: axNode.children ? axNode.children.map(axNodeFromProtocol) : undefined,
- };
- delete (result as any).valueNumber;
- delete (result as any).valueString;
- return result;
-}
-
-export class Accessibility implements api.Accessibility {
- private _channel: channels.PageChannel;
-
- constructor(channel: channels.PageChannel) {
- this._channel = channel;
- }
-
- async snapshot(options: { interestingOnly?: boolean; root?: ElementHandle } = {}): Promise<SerializedAXNode | null> {
- const root = options.root ? options.root._elementChannel : undefined;
- const result = await this._channel.accessibilitySnapshot({ interestingOnly: options.interestingOnly, root });
- return result.rootAXNode ? axNodeFromProtocol(result.rootAXNode) : null;
- }
-}
diff --git a/packages/playwright-core/src/client/api.ts b/packages/playwright-core/src/client/api.ts
index 7273ea244a..a7dab63f18 100644
--- a/packages/playwright-core/src/client/api.ts
+++ b/packages/playwright-core/src/client/api.ts
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-export { Accessibility } from './accessibility';
export { Android, AndroidDevice, AndroidInput, AndroidSocket, AndroidWebView } from './android';
export { Browser } from './browser';
export { BrowserContext } from './browserContext';
diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.ts
index 79ea69fcde..7c9c68ff99 100644
--- a/packages/playwright-core/src/client/page.ts
+++ b/packages/playwright-core/src/client/page.ts
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-import { Accessibility } from './accessibility';
import { Artifact } from './artifact';
import { ChannelOwner } from './channelOwner';
import { evaluationScript } from './clientHelper';
@@ -89,7 +88,6 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
_routes: RouteHandler[] = [];
_webSocketRoutes: WebSocketRouteHandler[] = [];
- readonly accessibility: Accessibility;
readonly coverage: Coverage;
readonly keyboard: Keyboard;
readonly mouse: Mouse;
@@ -121,7 +119,6 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
this._browserContext = parent as unknown as BrowserContext;
this._timeoutSettings = new TimeoutSettings(this._platform, this._browserContext._timeoutSettings);
- this.accessibility = new Accessibility(this._channel);
this.keyboard = new Keyboard(this);
this.mouse = new Mouse(this);
this.request = this._browserContext.request;
diff --git a/packages/playwright-core/src/protocol/validator.ts b/packages/playwright-core/src/protocol/validator.ts
index 04feccfea6..a80cd2786c 100644
--- a/packages/playwright-core/src/protocol/validator.ts
+++ b/packages/playwright-core/src/protocol/validator.ts
@@ -97,35 +97,6 @@ scheme.SelectorEngine = tObject({
source: tString,
contentScript: tOptional(tBoolean),
});
-scheme.AXNode = tObject({
- role: tString,
- name: tString,
- valueString: tOptional(tString),
- valueNumber: tOptional(tFloat),
- description: tOptional(tString),
- keyshortcuts: tOptional(tString),
- roledescription: tOptional(tString),
- valuetext: tOptional(tString),
- disabled: tOptional(tBoolean),
- expanded: tOptional(tBoolean),
- focused: tOptional(tBoolean),
- modal: tOptional(tBoolean),
- multiline: tOptional(tBoolean),
- multiselectable: tOptional(tBoolean),
- readonly: tOptional(tBoolean),
- required: tOptional(tBoolean),
- selected: tOptional(tBoolean),
- checked: tOptional(tEnum(['checked', 'unchecked', 'mixed'])),
- pressed: tOptional(tEnum(['pressed', 'released', 'mixed'])),
- level: tOptional(tInt),
- valuemin: tOptional(tFloat),
- valuemax: tOptional(tFloat),
- autocomplete: tOptional(tString),
- haspopup: tOptional(tString),
- invalid: tOptional(tString),
- orientation: tOptional(tString),
- children: tOptional(tArray(tType('AXNode'))),
-});
scheme.SetNetworkCookie = tObject({
name: tString,
value: tString,
@@ -1425,13 +1396,6 @@ scheme.PageTouchscreenTapParams = tObject({
y: tFloat,
});
scheme.PageTouchscreenTapResult = tOptional(tObject({}));
-scheme.PageAccessibilitySnapshotParams = tObject({
- interestingOnly: tOptional(tBoolean),
- root: tOptional(tChannel(['ElementHandle'])),
-});
-scheme.PageAccessibilitySnapshotResult = tObject({
- rootAXNode: tOptional(tType('AXNode')),
-});
scheme.PagePageErrorsParams = tOptional(tObject({}));
scheme.PagePageErrorsResult = tObject({
errors: tArray(tType('SerializedError')),
diff --git a/packages/playwright-core/src/server/accessibility.ts b/packages/playwright-core/src/server/accessibility.ts
deleted file mode 100644
index fbf8012c95..0000000000
--- a/packages/playwright-core/src/server/accessibility.ts
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * Copyright 2018 Google Inc. All rights reserved.
- * Modifications copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import type * as dom from './dom';
-import type * as channels from '@protocol/channels';
-
-export interface AXNode {
- isInteresting(insideControl: boolean): boolean;
- isLeafNode(): boolean;
- isControl(): boolean;
- serialize(): channels.AXNode;
- children(): Iterable<AXNode>;
-}
-
-export class Accessibility {
- private _getAXTree: (needle?: dom.ElementHandle) => Promise<{tree: AXNode, needle: AXNode | null}>;
- constructor(getAXTree: (needle?: dom.ElementHandle) => Promise<{tree: AXNode, needle: AXNode | null}>) {
- this._getAXTree = getAXTree;
- }
-
- async snapshot(options: {
- interestingOnly?: boolean;
- root?: dom.ElementHandle;
- } = {}): Promise<channels.AXNode | null> {
- const {
- interestingOnly = true,
- root = null,
- } = options;
- const { tree, needle } = await this._getAXTree(root || undefined);
- if (!interestingOnly) {
- if (root)
- return needle && serializeTree(needle)[0];
- return serializeTree(tree)[0];
- }
-
- const interestingNodes: Set<AXNode> = new Set();
- collectInterestingNodes(interestingNodes, tree, false);
- if (root && (!needle || !interestingNodes.has(needle)))
- return null;
- return serializeTree(needle || tree, interestingNodes)[0];
- }
-}
-
-function collectInterestingNodes(collection: Set<AXNode>, node: AXNode, insideControl: boolean) {
- if (node.isInteresting(insideControl))
- collection.add(node);
- if (node.isLeafNode())
- return;
- insideControl = insideControl || node.isControl();
- for (const child of node.children())
- collectInterestingNodes(collection, child, insideControl);
-}
-
-function serializeTree(node: AXNode, whitelistedNodes?: Set<AXNode>): channels.AXNode[] {
- const children: channels.AXNode[] = [];
- for (const child of node.children())
- children.push(...serializeTree(child, whitelistedNodes));
-
- if (whitelistedNodes && !whitelistedNodes.has(node))
- return children;
-
- const serializedNode = node.serialize();
- if (children.length)
- serializedNode.children = children;
- return [serializedNode];
-}
diff --git a/packages/playwright-core/src/server/bidi/bidiPage.ts b/packages/playwright-core/src/server/bidi/bidiPage.ts
index e5ece31858..e2015ac125 100644
--- a/packages/playwright-core/src/server/bidi/bidiPage.ts
+++ b/packages/playwright-core/src/server/bidi/bidiPage.ts
@@ -28,7 +28,6 @@ import * as bidi from './third_party/bidiProtocol';
import * as network from '../network';
import type { RegisteredListener } from '../utils/eventsHelper';
-import type * as accessibility from '../accessibility';
import type * as frames from '../frames';
import type { InitScript, PageDelegate } from '../page';
import type { Progress } from '../progress';
@@ -576,10 +575,6 @@ export class BidiPage implements PageDelegate {
return await executionContext.remoteObjectForNodeId(to, nodeId) as dom.ElementHandle<T>;
}
- async getAccessibilityTree(needle?: dom.ElementHandle): Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}> {
- throw new Error('Method not implemented.');
- }
-
async inputActionEpilogue(): Promise<void> {
}
diff --git a/packages/playwright-core/src/server/chromium/crAccessibility.ts b/packages/playwright-core/src/server/chromium/crAccessibility.ts
deleted file mode 100644
index 539f3057c7..0000000000
--- a/packages/playwright-core/src/server/chromium/crAccessibility.ts
+++ /dev/null
@@ -1,304 +0,0 @@
-/**
- * Copyright 2018 Google Inc. All rights reserved.
- * Modifications copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the 'License');
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an 'AS IS' BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import type { CRSession } from './crConnection';
-import type { Protocol } from './protocol';
-import type * as accessibility from '../accessibility';
-import type * as dom from '../dom';
-import type * as channels from '@protocol/channels';
-
-export async function getAccessibilityTree(client: CRSession, needle?: dom.ElementHandle): Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}> {
- const { nodes } = await client.send('Accessibility.getFullAXTree');
- const tree = CRAXNode.createTree(client, nodes);
- return {
- tree,
- needle: needle ? await tree._findElement(needle) : null
- };
-}
-
-class CRAXNode implements accessibility.AXNode {
- _payload: Protocol.Accessibility.AXNode;
- _children: CRAXNode[] = [];
- private _richlyEditable = false;
- private _editable = false;
- private _focusable = false;
- private _expanded = false;
- private _hidden = false;
- private _name: string;
- private _role: string;
- private _cachedHasFocusableChild: boolean | undefined;
- private _client: CRSession;
-
- constructor(client: CRSession, payload: Protocol.Accessibility.AXNode) {
- this._client = client;
- this._payload = payload;
-
- this._name = this._payload.name ? this._payload.name.value : '';
- this._role = this._payload.role ? this._payload.role.value : 'Unknown';
-
- for (const property of this._payload.properties || []) {
- if (property.name === 'editable') {
- this._richlyEditable = property.value.value === 'richtext';
- this._editable = true;
- }
- if (property.name === 'focusable')
- this._focusable = property.value.value;
- if (property.name === 'expanded')
- this._expanded = property.value.value;
- if (property.name === 'hidden')
- this._hidden = property.value.value;
- }
- }
-
- private _isPlainTextField(): boolean {
- if (this._richlyEditable)
- return false;
- if (this._editable)
- return true;
- return this._role === 'textbox' || this._role === 'ComboBox' || this._role === 'searchbox';
- }
-
- private _isTextOnlyObject(): boolean {
- const role = this._role;
- return (role === 'LineBreak' || role === 'text' ||
- role === 'InlineTextBox' || role === 'StaticText');
- }
-
- private _hasFocusableChild(): boolean {
- if (this._cachedHasFocusableChild === undefined) {
- this._cachedHasFocusableChild = false;
- for (const child of this._children) {
- if (child._focusable || child._hasFocusableChild()) {
- this._cachedHasFocusableChild = true;
- break;
- }
- }
- }
- return this._cachedHasFocusableChild;
- }
-
- children() {
- return this._children;
- }
-
- async _findElement(element: dom.ElementHandle): Promise<CRAXNode | null> {
- const objectId = element._objectId;
- const { node: { backendNodeId } } = await this._client.send('DOM.describeNode', { objectId });
- const needle = this.find(node => node._payload.backendDOMNodeId === backendNodeId);
- return needle || null;
- }
-
- find(predicate: (arg0: CRAXNode) => boolean): CRAXNode | null {
- if (predicate(this))
- return this;
- for (const child of this._children) {
- const result = child.find(predicate);
- if (result)
- return result;
- }
- return null;
- }
-
- isLeafNode(): boolean {
- if (!this._children.length)
- return true;
-
- // These types of objects may have children that we use as internal
- // implementation details, but we want to expose them as leaves to platform
- // accessibility APIs because screen readers might be confused if they find
- // any children.
- if (this._isPlainTextField() || this._isTextOnlyObject())
- return true;
-
- // Roles whose children are only presentational according to the ARIA and
- // HTML5 Specs should be hidden from screen readers.
- // (Note that whilst ARIA buttons can have only presentational children, HTML5
- // buttons are allowed to have content.)
- switch (this._role) {
- case 'doc-cover':
- case 'graphics-symbol':
- case 'img':
- case 'Meter':
- case 'scrollbar':
- case 'slider':
- case 'separator':
- case 'progressbar':
- return true;
- default:
- break;
- }
-
- // Here and below: Android heuristics
- if (this._hasFocusableChild())
- return false;
- if (this._focusable && this._role !== 'WebArea' && this._role !== 'RootWebArea' && this._name)
- return true;
- if (this._role === 'heading' && this._name)
- return true;
- return false;
- }
-
- isControl(): boolean {
- switch (this._role) {
- case 'button':
- case 'checkbox':
- case 'ColorWell':
- case 'combobox':
- case 'DisclosureTriangle':
- case 'listbox':
- case 'menu':
- case 'menubar':
- case 'menuitem':
- case 'menuitemcheckbox':
- case 'menuitemradio':
- case 'radio':
- case 'scrollbar':
- case 'searchbox':
- case 'slider':
- case 'spinbutton':
- case 'switch':
- case 'tab':
- case 'textbox':
- case 'tree':
- return true;
- default:
- return false;
- }
- }
-
- isInteresting(insideControl: boolean): boolean {
- const role = this._role;
- if (role === 'Ignored' || this._hidden)
- return false;
-
- if (this._focusable || this._richlyEditable)
- return true;
-
- // If it's not focusable but has a control role, then it's interesting.
- if (this.isControl())
- return true;
-
- // A non focusable child of a control is not interesting
- if (insideControl)
- return false;
-
- return this.isLeafNode() && !!this._name;
- }
-
- normalizedRole() {
- switch (this._role) {
- case 'RootWebArea':
- return 'WebArea';
- case 'StaticText':
- return 'text';
- default:
- return this._role;
- }
- }
-
- serialize(): channels.AXNode {
- const properties: Map<string, number | string | boolean> = new Map();
- for (const property of this._payload.properties || [])
- properties.set(property.name.toLowerCase(), property.value.value);
- if (this._payload.description)
- properties.set('description', this._payload.description.value);
-
- const node: {[x in keyof channels.AXNode]: any} = {
- role: this.normalizedRole(),
- name: this._payload.name ? (this._payload.name.value || '') : '',
- };
-
- const userStringProperties: Array<keyof channels.AXNode> = [
- 'description',
- 'keyshortcuts',
- 'roledescription',
- 'valuetext',
- ];
- for (const userStringProperty of userStringProperties) {
- if (!properties.has(userStringProperty))
- continue;
- node[userStringProperty] = properties.get(userStringProperty);
- }
- const booleanProperties: Array<keyof channels.AXNode> = [
- 'disabled',
- 'expanded',
- 'focused',
- 'modal',
- 'multiline',
- 'multiselectable',
- 'readonly',
- 'required',
- 'selected',
- ];
- for (const booleanProperty of booleanProperties) {
- // WebArea's treat focus differently than other nodes. They report whether their frame has focus,
- // not whether focus is specifically on the root node.
- if (booleanProperty === 'focused' && (this._role === 'WebArea' || this._role === 'RootWebArea'))
- continue;
- const value = properties.get(booleanProperty);
- if (!value)
- continue;
- node[booleanProperty] = value;
- }
- const numericalProperties: Array<keyof channels.AXNode> = [
- 'level',
- 'valuemax',
- 'valuemin',
- ];
- for (const numericalProperty of numericalProperties) {
- if (!properties.has(numericalProperty))
- continue;
- node[numericalProperty] = properties.get(numericalProperty);
- }
- const tokenProperties: Array<keyof channels.AXNode> = [
- 'autocomplete',
- 'haspopup',
- 'invalid',
- 'orientation',
- ];
- for (const tokenProperty of tokenProperties) {
- const value = properties.get(tokenProperty);
- if (!value || value === 'false')
- continue;
- node[tokenProperty] = value;
- }
-
- const axNode = node as channels.AXNode;
- if (this._payload.value) {
- if (typeof this._payload.value.value === 'string')
- axNode.valueString = this._payload.value.value;
- if (typeof this._payload.value.value === 'number')
- axNode.valueNumber = this._payload.value.value;
- }
- if (properties.has('checked'))
- axNode.checked = properties.get('checked') === 'true' ? 'checked' : properties.get('checked') === 'false' ? 'unchecked' : 'mixed';
- if (properties.has('pressed'))
- axNode.pressed = properties.get('pressed') === 'true' ? 'pressed' : properties.get('pressed') === 'false' ? 'released' : 'mixed';
- return axNode;
- }
-
- static createTree(client: CRSession, payloads: Protocol.Accessibility.AXNode[]): CRAXNode {
- const nodeById: Map<string, CRAXNode> = new Map();
- for (const payload of payloads)
- nodeById.set(payload.nodeId, new CRAXNode(client, payload));
- for (const node of nodeById.values()) {
- for (const childId of node._payload.childIds || [])
- node._children.push(nodeById.get(childId)!);
- }
- return nodeById.values().next().value!;
- }
-}
diff --git a/packages/playwright-core/src/server/chromium/crPage.ts b/packages/playwright-core/src/server/chromium/crPage.ts
index 6d0a1b087e..716ce51c8f 100644
--- a/packages/playwright-core/src/server/chromium/crPage.ts
+++ b/packages/playwright-core/src/server/chromium/crPage.ts
@@ -28,7 +28,6 @@ import { helper } from '../helper';
import * as network from '../network';
import { Page, PageBinding, Worker } from '../page';
import { registry } from '../registry';
-import { getAccessibilityTree } from './crAccessibility';
import { CRBrowserContext } from './crBrowser';
import { CRCoverage } from './crCoverage';
import { DragManager } from './crDragDrop';
@@ -326,10 +325,6 @@ export class CRPage implements PageDelegate {
return this._sessionForHandle(handle)._adoptElementHandle<T>(handle, to);
}
- async getAccessibilityTree(needle?: dom.ElementHandle) {
- return getAccessibilityTree(this._mainFrameSession._client, needle);
- }
-
async inputActionEpilogue(): Promise<void> {
await this._mainFrameSession._client.send('Page.enable').catch(e => {});
}
diff --git a/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts b/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts
index 45aed2e4f5..4075201661 100644
--- a/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts
+++ b/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts
@@ -328,14 +328,6 @@ export class PageDispatcher extends Dispatcher<Page, channels.PageChannel, Brows
await this._page.touchscreen.tap(progress, params.x, params.y);
}
- async accessibilitySnapshot(params: channels.PageAccessibilitySnapshotParams, progress: Progress): Promise<channels.PageAccessibilitySnapshotResult> {
- const rootAXNode = await progress.race(this._page.accessibility.snapshot({
- interestingOnly: params.interestingOnly,
- root: params.root ? (params.root as ElementHandleDispatcher)._elementHandle : undefined
- }));
- return { rootAXNode: rootAXNode || undefined };
- }
-
async pdf(params: channels.PagePdfParams, progress: Progress): Promise<channels.PagePdfResult> {
if (!this._page.pdf)
throw new Error('PDF generation is only supported for Headless Chromium');
diff --git a/packages/playwright-core/src/server/firefox/ffAccessibility.ts b/packages/playwright-core/src/server/firefox/ffAccessibility.ts
deleted file mode 100644
index d8d56b58de..0000000000
--- a/packages/playwright-core/src/server/firefox/ffAccessibility.ts
+++ /dev/null
@@ -1,267 +0,0 @@
-/**
- * Copyright 2018 Google Inc. All rights reserved.
- * Modifications copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the 'License');
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an 'AS IS' BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import type * as accessibility from '../accessibility';
-import type { FFSession } from './ffConnection';
-import type { Protocol } from './protocol';
-import type * as dom from '../dom';
-import type * as channels from '@protocol/channels';
-
-export async function getAccessibilityTree(session: FFSession, needle?: dom.ElementHandle): Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}> {
- const objectId = needle ? needle._objectId : undefined;
- const { tree } = await session.send('Accessibility.getFullAXTree', { objectId });
- const axNode = new FFAXNode(tree);
- return {
- tree: axNode,
- needle: needle ? axNode._findNeedle() : null
- };
-}
-
-const FFRoleToARIARole = new Map(Object.entries({
- 'pushbutton': 'button',
- 'checkbutton': 'checkbox',
- 'editcombobox': 'combobox',
- 'content deletion': 'deletion',
- 'footnote': 'doc-footnote',
- 'non-native document': 'document',
- 'grouping': 'group',
- 'graphic': 'img',
- 'content insertion': 'insertion',
- 'animation': 'marquee',
- 'flat equation': 'math',
- 'menupopup': 'menu',
- 'check menu item': 'menuitemcheckbox',
- 'radio menu item': 'menuitemradio',
- 'listbox option': 'option',
- 'radiobutton': 'radio',
- 'statusbar': 'status',
- 'pagetab': 'tab',
- 'pagetablist': 'tablist',
- 'propertypage': 'tabpanel',
- 'entry': 'textbox',
- 'outline': 'tree',
- 'tree table': 'treegrid',
- 'outlineitem': 'treeitem',
-}));
-
-class FFAXNode implements accessibility.AXNode {
- _children: FFAXNode[];
- private _payload: Protocol.Accessibility.AXTree;
- private _editable: boolean;
- private _richlyEditable: boolean;
- private _focusable: boolean;
- private _expanded: boolean;
- private _name: string;
- private _role: string;
- private _cachedHasFocusableChild: boolean|undefined;
-
- constructor(payload: Protocol.Accessibility.AXTree) {
- this._payload = payload;
- this._children = (payload.children || []).map(x => new FFAXNode(x));
- this._editable = !!payload.editable;
- this._richlyEditable = this._editable && (payload.tag !== 'textarea' && payload.tag !== 'input');
- this._focusable = !!payload.focusable;
- this._expanded = !!payload.expanded;
- this._name = this._payload.name;
- this._role = this._payload.role;
- }
-
- _isPlainTextField(): boolean {
- if (this._richlyEditable)
- return false;
- if (this._editable)
- return true;
- return this._role === 'entry';
- }
-
- _isTextOnlyObject(): boolean {
- const role = this._role;
- return (role === 'text leaf' || role === 'text' || role === 'statictext');
- }
-
- _hasFocusableChild(): boolean {
- if (this._cachedHasFocusableChild === undefined) {
- this._cachedHasFocusableChild = false;
- for (const child of this._children) {
- if (child._focusable || child._hasFocusableChild()) {
- this._cachedHasFocusableChild = true;
- break;
- }
- }
- }
- return this._cachedHasFocusableChild;
- }
-
- children() {
- return this._children;
- }
-
- _findNeedle(): FFAXNode | null {
- if (this._payload.foundObject)
- return this;
- for (const child of this._children) {
- const found = child._findNeedle();
- if (found)
- return found;
- }
- return null;
- }
-
- isLeafNode(): boolean {
- if (!this._children.length)
- return true;
- // These types of objects may have children that we use as internal
- // implementation details, but we want to expose them as leaves to platform
- // accessibility APIs because screen readers might be confused if they find
- // any children.
- if (this._isPlainTextField() || this._isTextOnlyObject())
- return true;
- // Roles whose children are only presentational according to the ARIA and
- // HTML5 Specs should be hidden from screen readers.
- // (Note that whilst ARIA buttons can have only presentational children, HTML5
- // buttons are allowed to have content.)
- switch (this._role) {
- case 'graphic':
- case 'scrollbar':
- case 'slider':
- case 'separator':
- case 'progressbar':
- return true;
- default:
- break;
- }
- // Here and below: Android heuristics
- if (this._hasFocusableChild())
- return false;
- if (this._focusable && this._role !== 'document' && this._name)
- return true;
- if (this._role === 'heading' && this._name)
- return true;
- return false;
- }
-
- isControl(): boolean {
- switch (this._role) {
- case 'checkbutton':
- case 'check menu item':
- case 'check rich option':
- case 'combobox':
- case 'combobox option':
- case 'color chooser':
- case 'listbox':
- case 'listbox option':
- case 'listbox rich option':
- case 'popup menu':
- case 'menupopup':
- case 'menuitem':
- case 'menubar':
- case 'button':
- case 'pushbutton':
- case 'radiobutton':
- case 'radio menuitem':
- case 'scrollbar':
- case 'slider':
- case 'spinbutton':
- case 'switch':
- case 'pagetab':
- case 'entry':
- case 'tree table':
- return true;
- default:
- return false;
- }
- }
-
- isInteresting(insideControl: boolean): boolean {
- if (this._focusable || this._richlyEditable)
- return true;
- // If it's not focusable but has a control role, then it's interesting.
- if (this.isControl())
- return true;
- // A non focusable child of a control is not interesting
- if (insideControl)
- return false;
- return this.isLeafNode() && !!this._name.trim();
- }
-
- serialize(): channels.AXNode {
- const node: {[x in keyof channels.AXNode]: any} = {
- role: FFRoleToARIARole.get(this._role) || this._role,
- name: this._name || '',
- };
- const userStringProperties: Array<keyof channels.AXNode & keyof Protocol.Accessibility.AXTree> = [
- 'name',
- 'description',
- 'roledescription',
- 'valuetext',
- 'keyshortcuts',
- ];
- for (const userStringProperty of userStringProperties) {
- if (!(userStringProperty in this._payload))
- continue;
- node[userStringProperty] = this._payload[userStringProperty];
- }
- const booleanProperties: Array<keyof channels.AXNode & keyof Protocol.Accessibility.AXTree> = [
- 'disabled',
- 'expanded',
- 'focused',
- 'modal',
- 'multiline',
- 'multiselectable',
- 'readonly',
- 'required',
- 'selected',
- ];
- for (const booleanProperty of booleanProperties) {
- if (this._role === 'document' && booleanProperty === 'focused')
- continue; // document focusing is strange
- const value = this._payload[booleanProperty];
- if (!value)
- continue;
- node[booleanProperty] = value;
- }
- const numericalProperties: Array<keyof channels.AXNode & keyof Protocol.Accessibility.AXTree> = [
- 'level'
- ];
- for (const numericalProperty of numericalProperties) {
- if (!(numericalProperty in this._payload))
- continue;
- node[numericalProperty] = this._payload[numericalProperty];
- }
- const tokenProperties: Array<keyof channels.AXNode & keyof Protocol.Accessibility.AXTree> = [
- 'autocomplete',
- 'haspopup',
- 'orientation',
- ];
- for (const tokenProperty of tokenProperties) {
- const value = this._payload[tokenProperty];
- if (!value || value === 'false')
- continue;
- node[tokenProperty] = value;
- }
-
- const axNode = node as channels.AXNode;
- axNode.valueString = this._payload.value;
- if ('checked' in this._payload)
- axNode.checked = this._payload.checked === true ? 'checked' : this._payload.checked === 'mixed' ? 'mixed' : 'unchecked';
- if ('pressed' in this._payload)
- axNode.pressed = this._payload.pressed === true ? 'pressed' : 'released';
- if ('invalid' in this._payload)
- axNode.invalid = this._payload.invalid === true ? 'true' : 'false';
- return axNode;
- }
-}
diff --git a/packages/playwright-core/src/server/firefox/ffPage.ts b/packages/playwright-core/src/server/firefox/ffPage.ts
index bc7d917b72..3f5fbc2b28 100644
--- a/packages/playwright-core/src/server/firefox/ffPage.ts
+++ b/packages/playwright-core/src/server/firefox/ffPage.ts
@@ -20,7 +20,6 @@ import * as dialog from '../dialog';
import * as dom from '../dom';
import { InitScript } from '../page';
import { Page, Worker } from '../page';
-import { getAccessibilityTree } from './ffAccessibility';
import { FFSession } from './ffConnection';
import { createHandle, FFExecutionContext } from './ffExecutionContext';
import { RawKeyboardImpl, RawMouseImpl, RawTouchscreenImpl } from './ffInput';
@@ -537,10 +536,6 @@ export class FFPage implements PageDelegate {
return createHandle(to, result.remoteObject) as dom.ElementHandle<T>;
}
- async getAccessibilityTree(needle?: dom.ElementHandle) {
- return getAccessibilityTree(this._session, needle);
- }
-
async inputActionEpilogue(): Promise<void> {
}
diff --git a/packages/playwright-core/src/server/page.ts b/packages/playwright-core/src/server/page.ts
index 2d829e4e84..ae67a847d8 100644
--- a/packages/playwright-core/src/server/page.ts
+++ b/packages/playwright-core/src/server/page.ts
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-import * as accessibility from './accessibility';
import { BrowserContext } from './browserContext';
import { ConsoleMessage } from './console';
import { TargetClosedError, TimeoutError } from './errors';
@@ -81,7 +80,6 @@ export interface PageDelegate {
scrollRectIntoViewIfNeeded(handle: dom.ElementHandle, rect?: types.Rect): Promise<'error:notvisible' | 'error:notconnected' | 'done'>;
setScreencastOptions(options: { width: number, height: number, quality: number } | null): Promise<void>;
- getAccessibilityTree(needle?: dom.ElementHandle): Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}>;
pdf?: (options: channels.PagePdfParams) => Promise<Buffer>;
coverage?: () => any;
@@ -155,7 +153,6 @@ export class Page extends SdkObject {
initScripts: InitScript[] = [];
readonly screenshotter: Screenshotter;
readonly frameManager: frames.FrameManager;
- readonly accessibility: accessibility.Accessibility;
private _workers = new Map<string, Worker>();
readonly pdf: ((options: channels.PagePdfParams) => Promise<Buffer>) | undefined;
readonly coverage: any;
@@ -178,7 +175,6 @@ export class Page extends SdkObject {
this.attribution.page = this;
this.delegate = delegate;
this.browserContext = browserContext;
- this.accessibility = new accessibility.Accessibility(delegate.getAccessibilityTree.bind(delegate));
this.keyboard = new input.Keyboard(delegate.rawKeyboard, this);
this.mouse = new input.Mouse(delegate.rawMouse, this);
this.touchscreen = new input.Touchscreen(delegate.rawTouchscreen, this);
diff --git a/packages/playwright-core/src/server/webkit/wkAccessibility.ts b/packages/playwright-core/src/server/webkit/wkAccessibility.ts
deleted file mode 100644
index 52b9199df5..0000000000
--- a/packages/playwright-core/src/server/webkit/wkAccessibility.ts
+++ /dev/null
@@ -1,268 +0,0 @@
-/**
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import type * as accessibility from '../accessibility';
-import type { Protocol } from './protocol';
-import type { WKSession } from './wkConnection';
-import type * as dom from '../dom';
-import type * as channels from '@protocol/channels';
-
-export async function getAccessibilityTree(session: WKSession, needle?: dom.ElementHandle) {
- const objectId = needle ? needle._objectId : undefined;
- const { axNode } = await session.send('Page.accessibilitySnapshot', { objectId });
- const tree = new WKAXNode(axNode);
- return {
- tree,
- needle: needle ? tree._findNeedle() : null
- };
-}
-
-const WKRoleToARIARole = new Map(Object.entries({
- 'TextField': 'textbox',
-}));
-
-// WebKit localizes role descriptions on mac, but the english versions only add noise.
-const WKUnhelpfulRoleDescriptions = new Map(Object.entries({
- 'WebArea': 'HTML content',
- 'Summary': 'summary',
- 'DescriptionList': 'description list',
- 'ImageMap': 'image map',
- 'ListMarker': 'list marker',
- 'Video': 'video playback',
- 'Mark': 'highlighted',
- 'contentinfo': 'content information',
- 'Details': 'details',
- 'DescriptionListDetail': 'description',
- 'DescriptionListTerm': 'term',
- 'alertdialog': 'web alert dialog',
- 'dialog': 'web dialog',
- 'status': 'application status',
- 'tabpanel': 'tab panel',
- 'application': 'web application',
-}));
-
-class WKAXNode implements accessibility.AXNode {
- private _payload: Protocol.Page.AXNode;
- private _children: WKAXNode[];
-
- constructor(payload: Protocol.Page.AXNode) {
- this._payload = payload;
-
- this._children = [];
- for (const payload of this._payload.children || [])
- this._children.push(new WKAXNode(payload));
- }
-
- children() {
- return this._children;
- }
-
- _findNeedle(): WKAXNode | null {
- if (this._payload.found)
- return this;
- for (const child of this._children) {
- const found = child._findNeedle();
- if (found)
- return found;
- }
- return null;
- }
-
- isControl(): boolean {
- switch (this._payload.role) {
- case 'button':
- case 'checkbox':
- case 'ColorWell':
- case 'combobox':
- case 'DisclosureTriangle':
- case 'listbox':
- case 'menu':
- case 'menubar':
- case 'menuitem':
- case 'menuitemcheckbox':
- case 'menuitemradio':
- case 'radio':
- case 'scrollbar':
- case 'searchbox':
- case 'slider':
- case 'spinbutton':
- case 'switch':
- case 'tab':
- case 'textbox':
- case 'TextField':
- case 'tree':
- return true;
- default:
- return false;
- }
- }
-
- _isTextControl(): boolean {
- switch (this._payload.role) {
- case 'combobox':
- case 'searchfield':
- case 'textbox':
- case 'TextField':
- return true;
- }
- return false;
- }
-
- _name(): string {
- if (this._payload.role === 'text')
- return this._payload.value || '';
- return this._payload.name || '';
- }
-
- isInteresting(insideControl: boolean): boolean {
- const { role, focusable } = this._payload;
- const name = this._name();
- if (role === 'ScrollArea')
- return false;
- if (role === 'WebArea')
- return true;
-
- if (focusable || role === 'MenuListOption')
- return true;
-
- // If it's not focusable but has a control role, then it's interesting.
- if (this.isControl())
- return true;
-
- // A non focusable child of a control is not interesting
- if (insideControl)
- return false;
-
- return this.isLeafNode() && !!name;
- }
-
- _hasRedundantTextChild() {
- if (this._children.length !== 1)
- return false;
- const child = this._children[0];
- return child._payload.role === 'text' && this._payload.name === child._payload.value;
- }
-
- isLeafNode(): boolean {
- if (!this._children.length)
- return true;
- // WebKit on Linux ignores everything inside text controls, normalize this behavior
- if (this._isTextControl())
- return true;
- // WebKit for mac has text nodes inside heading, li, menuitem, a, and p nodes
- if (this._hasRedundantTextChild())
- return true;
- return false;
- }
-
- serialize(): channels.AXNode {
- const node: channels.AXNode = {
- role: WKRoleToARIARole.get(this._payload.role) || this._payload.role,
- name: this._name(),
- };
-
- if ('description' in this._payload && this._payload.description !== node.name)
- node.description = this._payload.description;
-
- if ('roledescription' in this._payload) {
- const roledescription = this._payload.roledescription;
- if (roledescription !== this._payload.role && WKUnhelpfulRoleDescriptions.get(this._payload.role) !== roledescription)
- node.roledescription = roledescription;
- }
-
- if ('value' in this._payload && this._payload.role !== 'text') {
- if (typeof this._payload.value === 'string')
- node.valueString = this._payload.value;
- else if (typeof this._payload.value === 'number')
- node.valueNumber = this._payload.value;
- }
-
- if ('checked' in this._payload)
- node.checked = this._payload.checked === 'true' ? 'checked' : this._payload.checked === 'false' ? 'unchecked' : 'mixed';
-
- if ('pressed' in this._payload)
- node.pressed = this._payload.pressed === 'true' ? 'pressed' : this._payload.pressed === 'false' ? 'released' : 'mixed';
-
- const userStringProperties: Array<keyof channels.AXNode & keyof Protocol.Page.AXNode> = [
- 'keyshortcuts',
- 'valuetext'
- ];
- for (const userStringProperty of userStringProperties) {
- if (!(userStringProperty in this._payload))
- continue;
- (node as any)[userStringProperty] = this._payload[userStringProperty];
- }
-
- const booleanProperties: Array<keyof channels.AXNode & keyof Protocol.Page.AXNode> = [
- 'disabled',
- 'expanded',
- 'focused',
- 'modal',
- 'multiselectable',
- 'readonly',
- 'required',
- 'selected',
- ];
- for (const booleanProperty of booleanProperties) {
- // WebArea and ScrollArea treat focus differently than other nodes. They report whether their frame has focus,
- // not whether focus is specifically on the root node.
- if (booleanProperty === 'focused' && (this._payload.role === 'WebArea' || this._payload.role === 'ScrollArea'))
- continue;
- const value = this._payload[booleanProperty];
- if (!value)
- continue;
- (node as any)[booleanProperty] = value;
- }
-
- const numericalProperties: Array<keyof channels.AXNode & keyof Protocol.Page.AXNode> = [
- 'level',
- 'valuemax',
- 'valuemin',
- ];
- for (const numericalProperty of numericalProperties) {
- if (!(numericalProperty in this._payload))
- continue;
- (node as any)[numericalProperty] = (this._payload as any)[numericalProperty];
- }
- const tokenProperties: Array<keyof channels.AXNode & keyof Protocol.Page.AXNode> = [
- 'autocomplete',
- 'haspopup',
- 'invalid',
- ];
- for (const tokenProperty of tokenProperties) {
- const value = (this._payload as any)[tokenProperty];
- if (!value || value === 'false')
- continue;
- (node as any)[tokenProperty] = value;
- }
-
- const orientationIsApplicable = new Set([
- 'ScrollArea',
- 'scrollbar',
- 'listbox',
- 'combobox',
- 'menu',
- 'tree',
- 'separator',
- 'slider',
- 'tablist',
- 'toolbar',
- ]);
- if (this._payload.orientation && orientationIsApplicable.has(this._payload.role))
- node.orientation = this._payload.orientation;
-
- return node;
- }
-}
diff --git a/packages/playwright-core/src/server/webkit/wkPage.ts b/packages/playwright-core/src/server/webkit/wkPage.ts
index 3f72bc19a3..7e4350b99c 100644
--- a/packages/playwright-core/src/server/webkit/wkPage.ts
+++ b/packages/playwright-core/src/server/webkit/wkPage.ts
@@ -30,7 +30,6 @@ import { TargetClosedError } from '../errors';
import { helper } from '../helper';
import * as network from '../network';
import { Page, PageBinding } from '../page';
-import { getAccessibilityTree } from './wkAccessibility';
import { WKSession } from './wkConnection';
import { createHandle, WKExecutionContext } from './wkExecutionContext';
import { RawKeyboardImpl, RawMouseImpl, RawTouchscreenImpl } from './wkInput';
@@ -43,7 +42,6 @@ import { translatePathToWSL } from './webkit';
import type { Protocol } from './protocol';
import type { WKBrowserContext } from './wkBrowser';
import type { RegisteredListener } from '../utils/eventsHelper';
-import type * as accessibility from '../accessibility';
import type * as frames from '../frames';
import type { JSHandle } from '../javascript';
import type { InitScript, PageDelegate } from '../page';
@@ -991,10 +989,6 @@ export class WKPage implements PageDelegate {
return createHandle(to, result.object) as dom.ElementHandle<T>;
}
- async getAccessibilityTree(needle?: dom.ElementHandle): Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}> {
- return getAccessibilityTree(this._session, needle);
- }
-
async inputActionEpilogue(): Promise<void> {
}
diff --git a/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts b/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts
index 01c64d1b3b..04cae05e60 100644
--- a/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts
+++ b/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts
@@ -127,7 +127,6 @@ export const methodMetainfo = new Map<string, { internal?: boolean, title?: stri
['Page.mouseClick', { title: 'Click', slowMo: true, snapshot: true, pausesBeforeAction: true, }],
['Page.mouseWheel', { title: 'Mouse wheel', slowMo: true, snapshot: true, pausesBeforeAction: true, }],
['Page.touchscreenTap', { title: 'Tap', slowMo: true, snapshot: true, pausesBeforeAction: true, }],
- ['Page.accessibilitySnapshot', { title: 'Accessibility snapshot', group: 'getter', }],
['Page.pageErrors', { title: 'Get page errors', group: 'getter', }],
['Page.pdf', { title: 'PDF', }],
['Page.requests', { title: 'Get network requests', group: 'getter', }],
diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts
index f360194364..d07ab6fc6c 100644
--- a/packages/playwright-core/types/types.d.ts
+++ b/packages/playwright-core/types/types.d.ts
@@ -5167,13 +5167,6 @@ export interface Page {
*/
workers(): Array<Worker>;
- /**
- * @deprecated This property is discouraged. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to
- * test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration
- * with Axe.
- */
- accessibility: Accessibility;
-
/**
* Playwright has ability to mock clock and passage of time.
*/
@@ -15772,97 +15765,6 @@ class TimeoutError extends Error {
}
-/**
- * The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is
- * used by assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or
- * [switches](https://en.wikipedia.org/wiki/Switch_access).
- *
- * Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that
- * might have wildly different output.
- *
- * Rendering engines of Chromium, Firefox and WebKit have a concept of "accessibility tree", which is then translated
- * into different platform-specific APIs. Accessibility namespace gives access to this Accessibility Tree.
- *
- * Most of the accessibility tree gets filtered out when converting from internal browser AX Tree to Platform-specific
- * AX-Tree or by assistive technologies themselves. By default, Playwright tries to approximate this filtering,
- * exposing only the "interesting" nodes of the tree.
- */
-export interface Accessibility {
- /**
- * Captures the current state of the accessibility tree. The returned object represents the root accessible node of
- * the page.
- *
- * **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`](https://playwright.dev/docs/api/class-accessibility#accessibility-snapshot-option-interesting-only)
- * is set to `false`.
- *
- * **Usage**
- *
- * An example of dumping the entire accessibility tree:
- *
- * ```js
- * const snapshot = await page.accessibility.snapshot();
- * console.log(snapshot);
- * ```
- *
- * An example of logging the focused node's name:
- *
- * ```js
- * const snapshot = await page.accessibility.snapshot();
- * const node = findFocusedNode(snapshot);
- * console.log(node && node.name);
- *
- * function findFocusedNode(node) {
- * if (node.focused)
- * return node;
- * for (const child of node.children || []) {
- * const foundNode = findFocusedNode(child);
- * if (foundNode)
- * return foundNode;
- * }
- * return null;
- * }
- * ```
- *
- * @deprecated This method is deprecated. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to test
- * page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration with
- * Axe.
- * @param options
- */
- snapshot(options?: AccessibilitySnapshotOptions): Promise<null|AccessibilityNode>;
-
-}
-
-type AccessibilityNode = {
- role: string;
- name: string;
- value?: string|number;
- description?: string;
- keyshortcuts?: string;
- roledescription?: string;
- valuetext?: string;
- disabled?: boolean;
- expanded?: boolean;
- focused?: boolean;
- modal?: boolean;
- multiline?: boolean;
- multiselectable?: boolean;
- readonly?: boolean;
- required?: boolean;
- selected?: boolean;
- checked?: boolean|"mixed";
- pressed?: boolean|"mixed";
- level?: number;
- valuemin?: number;
- valuemax?: number;
- autocomplete?: string;
- haspopup?: string;
- invalid?: string;
- orientation?: string;
- children?: AccessibilityNode[];
-}
-
export const devices: Devices;
//@ts-ignore this will be any if electron is not installed
@@ -21768,18 +21670,6 @@ export interface WebSocket {
}
-interface AccessibilitySnapshotOptions {
- /**
- * Prune uninteresting nodes from the tree. Defaults to `true`.
- */
- interestingOnly?: boolean;
-
- /**
- * The root DOM element for the snapshot. Defaults to the whole page.
- */
- root?: ElementHandle;
-}
-
export interface LaunchOptions {
/**
* **NOTE** Use custom browser args at your own risk, as some of them may break Playwright functionality.
diff --git a/packages/protocol/src/channels.d.ts b/packages/protocol/src/channels.d.ts
index 8b47c31fd2..979e0facfd 100644
--- a/packages/protocol/src/channels.d.ts
+++ b/packages/protocol/src/channels.d.ts
@@ -221,36 +221,6 @@ export type SelectorEngine = {
contentScript?: boolean,
};
-export type AXNode = {
- role: string,
- name: string,
- valueString?: string,
- valueNumber?: number,
- description?: string,
- keyshortcuts?: string,
- roledescription?: string,
- valuetext?: string,
- disabled?: boolean,
- expanded?: boolean,
- focused?: boolean,
- modal?: boolean,
- multiline?: boolean,
- multiselectable?: boolean,
- readonly?: boolean,
- required?: boolean,
- selected?: boolean,
- checked?: 'checked' | 'unchecked' | 'mixed',
- pressed?: 'pressed' | 'released' | 'mixed',
- level?: number,
- valuemin?: number,
- valuemax?: number,
- autocomplete?: string,
- haspopup?: string,
- invalid?: string,
- orientation?: string,
- children?: AXNode[],
-};
-
export type SetNetworkCookie = {
name: string,
value: string,
@@ -2090,7 +2060,6 @@ export interface PageChannel extends PageEventTarget, EventTargetChannel {
mouseClick(params: PageMouseClickParams, progress?: Progress): Promise<PageMouseClickResult>;
mouseWheel(params: PageMouseWheelParams, progress?: Progress): Promise<PageMouseWheelResult>;
touchscreenTap(params: PageTouchscreenTapParams, progress?: Progress): Promise<PageTouchscreenTapResult>;
- accessibilitySnapshot(params: PageAccessibilitySnapshotParams, progress?: Progress): Promise<PageAccessibilitySnapshotResult>;
pageErrors(params?: PagePageErrorsParams, progress?: Progress): Promise<PagePageErrorsResult>;
pdf(params: PagePdfParams, progress?: Progress): Promise<PagePdfResult>;
requests(params?: PageRequestsParams, progress?: Progress): Promise<PageRequestsResult>;
@@ -2481,17 +2450,6 @@ export type PageTouchscreenTapOptions = {
};
export type PageTouchscreenTapResult = void;
-export type PageAccessibilitySnapshotParams = {
- interestingOnly?: boolean,
- root?: ElementHandleChannel,
-};
-export type PageAccessibilitySnapshotOptions = {
- interestingOnly?: boolean,
- root?: ElementHandleChannel,
-};
-export type PageAccessibilitySnapshotResult = {
- rootAXNode?: AXNode,
-};
export type PagePageErrorsParams = {};
export type PagePageErrorsOptions = {};
export type PagePageErrorsResult = {
diff --git a/packages/protocol/src/protocol.yml b/packages/protocol/src/protocol.yml
index adc570f33b..7644615578 100644
--- a/packages/protocol/src/protocol.yml
+++ b/packages/protocol/src/protocol.yml
@@ -162,50 +162,6 @@ SelectorEngine:
contentScript: boolean?
-AXNode:
- type: object
- properties:
- role: string
- name: string
- valueString: string?
- valueNumber: float?
- description: string?
- keyshortcuts: string?
- roledescription: string?
- valuetext: string?
- disabled: boolean?
- expanded: boolean?
- focused: boolean?
- modal: boolean?
- multiline: boolean?
- multiselectable: boolean?
- readonly: boolean?
- required: boolean?
- selected: boolean?
- checked:
- type: enum?
- literals:
- - checked
- - unchecked
- - mixed
- pressed:
- type: enum?
- literals:
- - pressed
- - released
- - mixed
- level: int?
- valuemin: float?
- valuemax: float?
- autocomplete: string?
- haspopup: string?
- invalid: string?
- orientation: string?
- children:
- type: array?
- items: AXNode
-
-
SetNetworkCookie:
type: object
properties:
@@ -1923,15 +1879,6 @@ Page:
snapshot: true
pausesBeforeAction: true
- accessibilitySnapshot:
- title: Accessibility snapshot
- group: getter
- parameters:
- interestingOnly: boolean?
- root: ElementHandle?
- returns:
- rootAXNode: AXNode?
-
pageErrors:
title: Get page errors
group: getter
diff --git a/tests/page/page-accessibility.spec.ts b/tests/page/page-accessibility.spec.ts
deleted file mode 100644
index 3e95dfe047..0000000000
--- a/tests/page/page-accessibility.spec.ts
+++ /dev/null
@@ -1,364 +0,0 @@
-/**
- * Copyright 2018 Google Inc. All rights reserved.
- * Modifications copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import { test as it, expect } from './pageTest';
-import { chromiumVersionLessThan } from '../config/utils';
-
-it('should work @smoke', async ({ page, browserName, isMac }) => {
- it.skip(browserName === 'webkit' && isMac);
- await page.setContent(`
- <head>
- <title>Accessibility Test</title>
- </head>
- <body>
- <h1>Inputs</h1>
- <input placeholder="Empty input" autofocus />
- <input placeholder="readonly input" readonly />
- <input placeholder="disabled input" disabled />
- <input aria-label="Input with whitespace" value=" " />
- <input value="value only" />
- <input aria-placeholder="placeholder" value="and a value" />
- <div aria-hidden="true" id="desc">This is a description!</div>
- <input aria-placeholder="placeholder" value="and a value" aria-describedby="desc" />
- </body>`);
- // autofocus happens after a delay in chrome these days
- await page.waitForFunction(() => document.activeElement.hasAttribute('autofocus'));
-
- const golden = (browserName === 'firefox') ? {
- role: 'document',
- name: 'Accessibility Test',
- children: [
- { role: 'heading', name: 'Inputs', level: 1 },
- { role: 'textbox', name: 'Empty input', focused: true },
- { role: 'textbox', name: 'readonly input', readonly: true },
- { role: 'textbox', name: 'disabled input', disabled: true },
- { role: 'textbox', name: 'Input with whitespace', value: ' ' },
- { role: 'textbox', name: '', value: 'value only' },
- { role: 'textbox', name: '', value: 'and a value' }, // firefox doesn't use aria-placeholder for the name
- { role: 'textbox', name: '', value: 'and a value', description: 'This is a description!' }, // and here
- ]
- } : (browserName === 'chromium') ? {
- role: 'WebArea',
- name: 'Accessibility Test',
- children: [
- { role: 'heading', name: 'Inputs', level: 1 },
- { role: 'textbox', name: 'Empty input', focused: true },
- { role: 'textbox', name: 'readonly input', readonly: true },
- { role: 'textbox', name: 'disabled input', disabled: true },
- { role: 'textbox', name: 'Input with whitespace', value: ' ' },
- { role: 'textbox', name: '', value: 'value only' },
- { role: 'textbox', name: 'placeholder', value: 'and a value' },
- { role: 'textbox', name: 'placeholder', value: 'and a value', description: 'This is a description!' },
- ]
- } : {
- role: 'WebArea',
- name: 'Accessibility Test',
- children: [
- { role: 'heading', name: 'Inputs', level: 1 },
- { role: 'textbox', name: 'Empty input', focused: true },
- { role: 'textbox', name: 'readonly input', readonly: true },
- { role: 'textbox', name: 'disabled input', disabled: true },
- { role: 'textbox', name: 'Input with whitespace', value: ' ' },
- { role: 'textbox', name: '', value: 'value only' },
- { role: 'textbox', name: 'placeholder', value: 'and a value' },
- { role: 'textbox', name: isMac ? 'placeholder' : 'This is a description!', value: 'and a value' },
- ]
- };
- expect(await page.accessibility.snapshot()).toEqual(golden);
-});
-
-it('should work with regular text', async ({ page, browserName }) => {
- await page.setContent(`<div>Hello World</div>`);
- const snapshot = await page.accessibility.snapshot();
- expect(snapshot.children[0]).toEqual({
- role: browserName === 'firefox' ? 'text leaf' : 'text',
- name: 'Hello World',
- });
-});
-
-it('roledescription', async ({ page }) => {
- await page.setContent('<p tabIndex=-1 aria-roledescription="foo">Hi</p>');
- const snapshot = await page.accessibility.snapshot();
- expect(snapshot.children[0].roledescription).toEqual('foo');
-});
-
-it('orientation', async ({ page }) => {
- await page.setContent('<a href="" role="slider" aria-orientation="vertical">11</a>');
- const snapshot = await page.accessibility.snapshot();
- expect(snapshot.children[0].orientation).toEqual('vertical');
-});
-
-it('autocomplete', async ({ page }) => {
- await page.setContent('<div role="textbox" aria-autocomplete="list" aria-haspopup="menu">hi</div>');
- const snapshot = await page.accessibility.snapshot();
- expect(snapshot.children[0].autocomplete).toEqual('list');
- expect(snapshot.children[0].haspopup).toEqual('menu');
-});
-
-it('multiselectable', async ({ page }) => {
- await page.setContent('<div role="grid" tabIndex=-1 aria-multiselectable=true>hey</div>');
- const snapshot = await page.accessibility.snapshot();
- expect(snapshot.children[0].multiselectable).toEqual(true);
-});
-
-it('keyshortcuts', async ({ page }) => {
- await page.setContent('<div role="grid" tabIndex=-1 aria-keyshortcuts="foo">hey</div>');
- const snapshot = await page.accessibility.snapshot();
- expect(snapshot.children[0].keyshortcuts).toEqual('foo');
-});
-
-it('should not report text nodes inside controls', async function({ page, browserName }) {
- await page.setContent(`
- <div role="tablist">
- <div role="tab" aria-selected="true"><b>Tab1</b></div>
- <div role="tab">Tab2</div>
- </div>`);
- const golden = {
- role: browserName === 'firefox' ? 'document' : 'WebArea',
- name: '',
- children: [{
- role: 'tab',
- name: 'Tab1',
- selected: true
- }, {
- role: 'tab',
- name: 'Tab2'
- }]
- };
- expect(await page.accessibility.snapshot()).toEqual(golden);
-});
-
-it('rich text editable fields should have children', async function({ page, browserName, browserVersion }) {
- it.skip(browserName === 'webkit', 'WebKit rich text accessibility is iffy');
-
- await page.setContent(`
- <div contenteditable="true">
- Edit this image: <img src="fakeimage.png" alt="my fake image">
- </div>`);
- const golden = browserName === 'firefox' ? {
- role: 'section',
- name: '',
- children: [{
- role: 'text leaf',
- name: 'Edit this image: '
- }, {
- role: 'text',
- name: 'my fake image'
- }]
- } : {
- role: 'generic',
- name: '',
- value: 'Edit this image: ',
- children: [{
- role: 'text',
- name: chromiumVersionLessThan(browserVersion, '108.0.5325.0') ? 'Edit this image:' : 'Edit this image: '
- }, {
- role: chromiumVersionLessThan(browserVersion, '117.0.5927.0') ? 'img' : 'image',
- name: 'my fake image'
- }]
- };
- const snapshot = await page.accessibility.snapshot();
- expect(snapshot.children[0]).toEqual(golden);
-});
-
-it('rich text editable fields with role should have children', async function({ page, browserName, browserVersion }) {
- it.skip(browserName === 'webkit', 'WebKit rich text accessibility is iffy');
-
- await page.setContent(`
- <div contenteditable="true" role='textbox'>
- Edit this image: <img src="fakeimage.png" alt="my fake image">
- </div>`);
- const golden = browserName === 'firefox' ? {
- role: 'textbox',
- name: '',
- value: 'Edit this image: my fake image',
- children: [{
- role: 'text',
- name: 'my fake image'
- }]
- } : {
- role: 'textbox',
- name: '',
- multiline: (browserName === 'chromium') ? true : undefined,
- value: 'Edit this image: ',
- children: (chromiumVersionLessThan(browserVersion, '104.0.1293.1') && browserName === 'chromium') ? [{
- role: 'text',
- name: 'Edit this image:'
- }, {
- role: 'img',
- name: 'my fake image'
- }] : [{
- role: 'text',
- name: chromiumVersionLessThan(browserVersion, '108.0.5325.0') ? 'Edit this image:' : 'Edit this image: '
- }]
- };
- const snapshot = await page.accessibility.snapshot();
- expect(snapshot.children[0]).toEqual(golden);
-});
-
-it('non editable textbox with role and tabIndex and label should not have children', async function({ page, browserName }) {
- await page.setContent(`
- <div role="textbox" tabIndex=0 aria-checked="true" aria-label="my favorite textbox">
- this is the inner content
- <img alt="yo" src="fakeimg.png">
- </div>`);
- const golden = (browserName === 'firefox') ? {
- role: 'textbox',
- name: 'my favorite textbox',
- value: 'this is the inner content yo'
- } : (browserName === 'chromium') ? {
- role: 'textbox',
- name: 'my favorite textbox',
- value: 'this is the inner content '
- } : {
- role: 'textbox',
- name: 'my favorite textbox',
- value: 'this is the inner content ',
- };
- const snapshot = await page.accessibility.snapshot();
- expect(snapshot.children[0]).toEqual(golden);
-});
-
-it('checkbox with and tabIndex and label should not have children', async function({ page }) {
- await page.setContent(`
- <div role="checkbox" tabIndex=0 aria-checked="true" aria-label="my favorite checkbox">
- this is the inner content
- <img alt="yo" src="fakeimg.png">
- </div>`);
- const golden = {
- role: 'checkbox',
- name: 'my favorite checkbox',
- checked: true
- };
- const snapshot = await page.accessibility.snapshot();
- expect(snapshot.children[0]).toEqual(golden);
-});
-
-it('checkbox without label should not have children', async ({ page, browserName }) => {
- await page.setContent(`
- <div role="checkbox" aria-checked="true">
- this is the inner content
- <img alt="yo" src="fakeimg.png">
- </div>`);
- const golden = browserName === 'firefox' ? {
- role: 'checkbox',
- name: 'this is the inner content yo',
- checked: true
- } : {
- role: 'checkbox',
- name: 'this is the inner content yo',
- checked: true
- };
- const snapshot = await page.accessibility.snapshot();
- expect(snapshot.children[0]).toEqual(golden);
-});
-
-it('should work a button', async ({ page }) => {
- await page.setContent(`<button>My Button</button>`);
-
- const button = await page.$('button');
- expect(await page.accessibility.snapshot({ root: button })).toEqual({
- role: 'button',
- name: 'My Button'
- });
-});
-
-it('should work an input', async ({ page }) => {
- await page.setContent(`<input title="My Input" value="My Value">`);
-
- const input = await page.$('input');
- expect(await page.accessibility.snapshot({ root: input })).toEqual({
- role: 'textbox',
- name: 'My Input',
- value: 'My Value'
- });
-});
-
-it('should work on a menu', async ({ page, browserName, browserVersion }) => {
- await page.setContent(`
- <div role="menu" title="My Menu">
- <div role="menuitem">First Item</div>
- <div role="menuitem">Second Item</div>
- <div role="menuitem">Third Item</div>
- </div>
- `);
-
- const menu = await page.$('div[role="menu"]');
- expect(await page.accessibility.snapshot({ root: menu })).toEqual({
- role: 'menu',
- name: 'My Menu',
- children:
- [{ role: 'menuitem', name: 'First Item' },
- { role: 'menuitem', name: 'Second Item' },
- { role: 'menuitem', name: 'Third Item' }],
- orientation: (browserName === 'webkit' || (browserName === 'chromium' && !chromiumVersionLessThan(browserVersion, '98.0.1089'))) ? 'vertical' : undefined
- });
-});
-
-it('should return null when the element is no longer in DOM', async ({ page }) => {
- await page.setContent(`<button>My Button</button>`);
- const button = await page.$('button');
- await page.$eval('button', button => button.remove());
- expect(await page.accessibility.snapshot({ root: button })).toEqual(null);
-});
-
-it('should show uninteresting nodes', async ({ page }) => {
- await page.setContent(`
- <div id="root" role="textbox">
- <div>
- hello
- <div>
- world
- </div>
- </div>
- </div>
- `);
-
- const root = await page.$('#root');
- const snapshot = await page.accessibility.snapshot({ root, interestingOnly: false });
- expect(snapshot.role).toBe('textbox');
- expect(snapshot.value).toContain('hello');
- expect(snapshot.value).toContain('world');
- expect(!!snapshot.children).toBe(true);
-});
-
-it('should work when there is a title ', async ({ page }) => {
- await page.setContent(`
- <title>This is the title</title>
- <div>This is the content</div>
- `);
- const snapshot = await page.accessibility.snapshot();
- expect(snapshot.name).toBe('This is the title');
- expect(snapshot.children[0].name).toBe('This is the content');
-});
-
-it('should work with aria-invalid accessibility tree', async ({ page, browserName, server }) => {
- await page.goto(server.EMPTY_PAGE);
- await page.setContent(`<a href="/hi" aria-invalid="true">WHO WE ARE</a>`);
- expect(await page.accessibility.snapshot()).toEqual({
- 'role': browserName === 'firefox' ? 'document' : 'WebArea',
- 'name': '',
- 'children': [
- {
- 'role': 'link',
- 'name': 'WHO WE ARE',
- 'invalid': 'true',
- 'value': browserName === 'firefox' ? `${server.PREFIX}/hi` : undefined
- }
- ]
- });
-});
diff --git a/utils/generate_types/overrides.d.ts b/utils/generate_types/overrides.d.ts
index 2dad53c848..f5dca77433 100644
--- a/utils/generate_types/overrides.d.ts
+++ b/utils/generate_types/overrides.d.ts
@@ -244,39 +244,6 @@ class TimeoutError extends Error {}
}
-export interface Accessibility {
- snapshot(options?: AccessibilitySnapshotOptions): Promise<null|AccessibilityNode>;
-}
-
-type AccessibilityNode = {
- role: string;
- name: string;
- value?: string|number;
- description?: string;
- keyshortcuts?: string;
- roledescription?: string;
- valuetext?: string;
- disabled?: boolean;
- expanded?: boolean;
- focused?: boolean;
- modal?: boolean;
- multiline?: boolean;
- multiselectable?: boolean;
- readonly?: boolean;
- required?: boolean;
- selected?: boolean;
- checked?: boolean|"mixed";
- pressed?: boolean|"mixed";
- level?: number;
- valuemin?: number;
- valuemax?: number;
- autocomplete?: string;
- haspopup?: string;
- invalid?: string;
- orientation?: string;
- children?: AccessibilityNode[];
-}
-
export const devices: Devices;
//@ts-ignore this will be any if electron is not installed