mirror of
https://github.com/hanzoai/puppeteer.git
synced 2026-09-24 17:02:14 +00:00
chore: return loaderId in a11y snapshots (#14591)
This commit is contained in:
@@ -8,6 +8,7 @@ import type {Protocol} from 'devtools-protocol';
|
||||
|
||||
import type {ElementHandle} from '../api/ElementHandle.js';
|
||||
import type {Realm} from '../api/Realm.js';
|
||||
import type {CdpFrame} from '../cdp/Frame.js';
|
||||
import {debugError} from '../common/util.js';
|
||||
|
||||
/**
|
||||
@@ -88,12 +89,19 @@ export interface SerializedAXNode {
|
||||
children?: SerializedAXNode[];
|
||||
|
||||
/**
|
||||
* CDP-specifc ID to reference the DOM node.
|
||||
* CDP-specific ID to reference the DOM node.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
backendNodeId?: number;
|
||||
|
||||
/**
|
||||
* CDP-specific documentId.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
loaderId: string;
|
||||
|
||||
/**
|
||||
* Get an ElementHandle for this AXNode if available.
|
||||
*
|
||||
@@ -553,6 +561,9 @@ class AXNode {
|
||||
})) as ElementHandle<Element>;
|
||||
},
|
||||
backendNodeId: this.payload.backendDOMNodeId,
|
||||
// LoaderId is an experimental mechanism to establish unique IDs across
|
||||
// navigations.
|
||||
loaderId: (this.#realm.environment as CdpFrame)._loaderId,
|
||||
};
|
||||
|
||||
type UserStringProperty =
|
||||
|
||||
@@ -230,6 +230,13 @@
|
||||
"expectations": ["SKIP"],
|
||||
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[a11yLoaderId.spec] Accessibility loaderId should match loaderId for iframes",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["webDriverBiDi"],
|
||||
"expectations": ["SKIP"],
|
||||
"comment": "not supported, CDP-specific test"
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[accessibility.spec] *",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import expect from 'expect';
|
||||
import type {CdpFrame} from 'puppeteer-core/internal/cdp/Frame.js';
|
||||
|
||||
import {getTestState, setupTestBrowserHooks} from '../mocha-utils.js';
|
||||
import {attachFrame} from '../utils.js';
|
||||
|
||||
describe('Accessibility loaderId', function () {
|
||||
setupTestBrowserHooks();
|
||||
|
||||
it('should match loaderId for iframes', async () => {
|
||||
const {page, server} = await getTestState();
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
||||
const frame1 = page.frames()[1];
|
||||
await frame1!.evaluate(() => {
|
||||
const button = document.createElement('button');
|
||||
button.innerText = 'value1';
|
||||
document.body.appendChild(button);
|
||||
});
|
||||
const snapshot = await page.accessibility.snapshot({
|
||||
interestingOnly: true,
|
||||
includeIframes: true,
|
||||
});
|
||||
|
||||
const mainLoaderId = (page.mainFrame() as CdpFrame)._loaderId;
|
||||
const frame1LoaderId = (frame1 as CdpFrame)._loaderId;
|
||||
|
||||
expect(typeof mainLoaderId).toBe('string');
|
||||
expect(mainLoaderId).toBeTruthy();
|
||||
expect(typeof frame1LoaderId).toBe('string');
|
||||
expect(frame1LoaderId).toBeTruthy();
|
||||
|
||||
expect(snapshot).toMatchObject({
|
||||
role: 'RootWebArea',
|
||||
name: '',
|
||||
loaderId: mainLoaderId,
|
||||
children: [
|
||||
{
|
||||
role: 'Iframe',
|
||||
name: '',
|
||||
loaderId: mainLoaderId,
|
||||
children: [
|
||||
{
|
||||
role: 'RootWebArea',
|
||||
name: '',
|
||||
loaderId: frame1LoaderId,
|
||||
children: [
|
||||
{
|
||||
role: 'button',
|
||||
name: 'value1',
|
||||
loaderId: frame1LoaderId,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user