chore(aria): always include iframe (#35527)

This commit is contained in:
Simon Knott 2025-04-08 11:32:59 +02:00 committed by GitHub
parent 668bf580d7
commit 815938b065
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 11 deletions

View File

@ -38,7 +38,7 @@ export type AriaSnapshot = {
ids: Builtins.Map<Element, number>;
};
export function generateAriaTree(builtins: Builtins, rootElement: Element, generation: number, includeIframe: boolean): AriaSnapshot {
export function generateAriaTree(builtins: Builtins, rootElement: Element, generation: number): AriaSnapshot {
const visited = new builtins.Set<Node>();
const snapshot: AriaSnapshot = {
@ -87,7 +87,7 @@ export function generateAriaTree(builtins: Builtins, rootElement: Element, gener
}
addElement(element);
const childAriaNode = toAriaNode(builtins, element, includeIframe);
const childAriaNode = toAriaNode(builtins, element);
if (childAriaNode)
ariaNode.children.push(childAriaNode);
processElement(childAriaNode || ariaNode, element, ariaChildren);
@ -144,8 +144,8 @@ export function generateAriaTree(builtins: Builtins, rootElement: Element, gener
return snapshot;
}
function toAriaNode(builtins: Builtins, element: Element, includeIframe: boolean): AriaNode | null {
if (includeIframe && element.nodeName === 'IFRAME')
function toAriaNode(builtins: Builtins, element: Element): AriaNode | null {
if (element.nodeName === 'IFRAME')
return { role: 'iframe', name: '', children: [], props: {}, element };
const role = roleUtils.getAriaRole(element);
@ -235,7 +235,7 @@ export type MatcherReceived = {
};
export function matchesAriaTree(builtins: Builtins, rootElement: Element, template: AriaTemplateNode): { matches: AriaNode[], received: MatcherReceived } {
const snapshot = generateAriaTree(builtins, rootElement, 0, false);
const snapshot = generateAriaTree(builtins, rootElement, 0);
const matches = matchesNodeDeep(snapshot.root, template, false, false);
return {
matches,
@ -247,7 +247,7 @@ export function matchesAriaTree(builtins: Builtins, rootElement: Element, templa
}
export function getAllByAria(builtins: Builtins, rootElement: Element, template: AriaTemplateNode): Element[] {
const root = generateAriaTree(builtins, rootElement, 0, false).root;
const root = generateAriaTree(builtins, rootElement, 0).root;
const matches = matchesNodeDeep(root, template, true, false);
return matches.map(n => n.element);
}

View File

@ -284,7 +284,7 @@ export class InjectedScript {
if (node.nodeType !== Node.ELEMENT_NODE)
throw this.createStacklessError('Can only capture aria snapshot of Element nodes.');
const generation = (this._lastAriaSnapshot?.generation || 0) + 1;
this._lastAriaSnapshot = generateAriaTree(this.builtins, node as Element, generation, options?.ref ?? false);
this._lastAriaSnapshot = generateAriaTree(this.builtins, node as Element, generation);
return renderAriaTree(this._lastAriaSnapshot, options);
}

View File

@ -684,17 +684,17 @@ it('should generate refs', async ({ page }) => {
expect(e.message).toContain('Error: Stale aria-ref, expected s2e{number}, got s1e3');
});
it('ref mode should list iframes', async ({ page }) => {
it('should list iframes', async ({ page }) => {
await page.setContent(`
<h1>Hello</h1>
<iframe name="foo" src="data:text/html,<h1>World</h1>">
`);
const snapshot1 = await page.locator('body').ariaSnapshot({ ref: true });
expect(snapshot1).toContain('- iframe [ref=s1e4]');
expect(snapshot1).toContain('- iframe');
const frameSnapshot = await page.frameLocator(`aria-ref=s1e4`).locator('body').ariaSnapshot({ ref: true });
expect(frameSnapshot).toEqual('- heading "World" [level=1] [ref=s1e3]');
const frameSnapshot = await page.frameLocator(`iframe`).locator('body').ariaSnapshot();
expect(frameSnapshot).toEqual('- heading "World" [level=1]');
});
it('ref mode can be used to stitch all frame snapshots', async ({ page, server }) => {