Skip to content

Commit f03b373

Browse files
authored
Add missing accessibility test (#2303)
1 parent f9d2a9f commit f03b373

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

lib/PuppeteerSharp.Tests/AccessibilityTests/AccessibilityTests.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,57 @@ public async Task ShouldReportUninterestingNodes()
153153
})));
154154
}
155155

156+
[PuppeteerTest("accessibility.spec.ts", "Accessibility", "get snapshots while the tree is re-calculated")]
157+
[Skip(SkipAttribute.Targets.Firefox)]
158+
public async Task GetSnapshotsWhileTheTreeIsReCalculated()
159+
{
160+
await Page.SetContentAsync(@"
161+
<!DOCTYPE html>
162+
<html lang=""en"">
163+
<head>
164+
<meta charset=""UTF-8"">
165+
<meta http-equiv=""X-UA-Compatible"" content=""IE=edge"">
166+
<meta name=""viewport"" content=""width=device-width, initial-scale=1.0"">
167+
<title>Accessible name + aria-expanded puppeteer bug</title>
168+
<style>
169+
[aria-expanded=""false""] + * {
170+
display: none;
171+
}
172+
</style>
173+
</head>
174+
<body>
175+
<button hidden>Show</button>
176+
<p>Some content</p>
177+
<script>
178+
const button = document.querySelector('button');
179+
button.removeAttribute('hidden')
180+
button.setAttribute('aria-expanded', 'false');
181+
button.addEventListener('click', function() {
182+
button.setAttribute('aria-expanded', button.getAttribute('aria-expanded') !== 'true')
183+
if (button.getAttribute('aria-expanded') == 'true') {
184+
button.textContent = 'Hide'
185+
} else {
186+
button.textContent = 'Show'
187+
}
188+
})
189+
</script>
190+
</body>
191+
</html>");
192+
193+
var button = await Page.QuerySelectorAsync("button");
194+
Assert.AreEqual("Show", await GetAccessibleNameAsync(Page, button));
195+
await button?.ClickAsync();
196+
await Page.WaitForSelectorAsync("aria/Hide");
197+
}
198+
199+
private async Task<string> GetAccessibleNameAsync(IPage page, IElementHandle element)
200+
{
201+
return (await page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions
202+
{
203+
Root = element
204+
})).Name;
205+
}
206+
156207
[PuppeteerTest("accessibility.spec.ts", "Accessibility", "roledescription")]
157208
[Skip(SkipAttribute.Targets.Firefox)]
158209
public async Task RoleDescription()

0 commit comments

Comments
 (0)