Skip to content

Commit

Permalink
fix: improve a11y snapshot handling if the tree is not correct (#9405)
Browse files Browse the repository at this point in the history
Bug #9404
  • Loading branch information
OrKoN committed Dec 13, 2022
1 parent a304543 commit 02fe501
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/puppeteer-core/src/common/Accessibility.ts
Expand Up @@ -564,7 +564,10 @@ class AXNode {
}
for (const node of nodeById.values()) {
for (const childId of node.payload.childIds || []) {
node.children.push(nodeById.get(childId)!);
const child = nodeById.get(childId);
if (child) {
node.children.push(child);
}
}
}
return nodeById.values().next().value;
Expand Down
45 changes: 45 additions & 0 deletions test/src/accessibility.spec.ts
Expand Up @@ -163,6 +163,51 @@ describe('Accessibility', function () {
)
).toEqual(golden);
});
it('get snapshots while the tree is re-calculated', async () => {
// see https://github.com/puppeteer/puppeteer/issues/9404
const {page} = getTestState();

await page.setContent(
`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accessible name + aria-expanded puppeteer bug</title>
<style>
[aria-expanded="false"] + * {
display: none;
}
</style>
</head>
<body>
<button hidden>Show</button>
<p>Some content</p>
<script>
const button = document.querySelector('button');
button.removeAttribute('hidden')
button.setAttribute('aria-expanded', 'false');
button.addEventListener('click', function() {
button.setAttribute('aria-expanded', button.getAttribute('aria-expanded') !== 'true')
if (button.getAttribute('aria-expanded') == 'true') {
button.textContent = 'Hide'
} else {
button.textContent = 'Show'
}
})
</script>
</body>
</html>`
);
async function getAccessibleName(page: any, element: any) {
return (await page.accessibility.snapshot({root: element})).name;
}
const button = await page.$('button');
expect(await getAccessibleName(page, button)).toEqual('Show');
await button?.click();
await page.waitForSelector('aria/Hide');
});
it('roledescription', async () => {
const {page} = getTestState();

Expand Down

0 comments on commit 02fe501

Please sign in to comment.