playwright
playwright copied to clipboard
feat: add aria-busy support to role selectors
Closes https://github.com/microsoft/playwright/issues/36233
Summary
This PR adds support for the aria-busy attribute to Playwright's role selector functionality, allowing developers to identify elements based on their busy state.
Changes
- Core Implementation: Added
getAriaBusy()function inroleUtils.tsthat usesgetAriaBoolean()to check thearia-busyattribute - Role Selector Engine: Added
busyoption support to role selector engine with proper validation - TypeScript Support: Added
busy?: booleanproperty toByRoleOptionstype inlocatorUtils.ts - Documentation: Added comprehensive documentation for the
busyoption in API docs - Testing: Added thorough tests covering all busy attribute scenarios
Usage Examples
API syntax:
// Find busy buttons
await page.getByRole('button', { busy: true }).click();
// Find non-busy buttons
await page.getByRole('button', { busy: false }).click();
Behavior
- Elements without an
aria-busyattribute are treated asbusy=false(following ARIA specification) - Elements with
aria-busy="true"are treated asbusy=true - Elements with
aria-busy="false"are treated asbusy=false - The
busyattribute can be applied to any role (no role restrictions, following ARIA global attribute guidelines)
Testing
All tests pass including:
- ✅ Basic busy/non-busy element detection
- ✅ Selector syntax (
role=button[busy],role=button[busy=true],role=button[busy=false]) - ✅ API syntax (
getByRole('button', { busy: true })) - ✅ Default behavior for elements without
aria-busyattribute - ✅ Integration with existing role selector functionality
- ✅ Error handling and validation
The implementation follows the same patterns as existing ARIA attributes (checked, disabled, selected, etc.) and maintains full backward compatibility.
Test results for "tests 1"
4 flaky
:warning: [firefox-library] › library/inspector/cli-codegen-1.spec.ts:986:7 › cli codegen › should not throw csp directive violation errors @firefox-ubuntu-22.04-node18:warning: [playwright-test] › ui-mode-trace.spec.ts:587:5 › should indicate current test status @macos-latest-node18-1
:warning: [webkit-page] › page/page-screenshot.spec.ts:345:5 › page screenshot › should work while navigating @webkit-ubuntu-22.04-node18
:warning: [playwright-test] › ui-mode-test-watch.spec.ts:145:5 › should watch all @windows-latest-node18-1
39360 passed, 820 skipped :heavy_check_mark::heavy_check_mark::heavy_check_mark:
Merge workflow run.
@microsoft-github-policy-service agree
Hi! We're trying to be mindful of expanding your API scope, so we need to have clear indicators for user need before we make additions like these. Let's wait a while to see how many upvotes https://github.com/microsoft/playwright/issues/36233 gathers. If it turns out being a popular request, we're more than happy to accept a PR.
Sounds good, thanks @Skn0tt 👍
@markmur I will close this PR for now, so that it's easier for us to triage and review open PRs. We'll reopen it when the feature becomes more popular and we are ready to ship it. Thank you!