playwright icon indicating copy to clipboard operation
playwright copied to clipboard

feat: add aria-busy support to role selectors

Open markmur opened this issue 5 months ago • 4 comments

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 in roleUtils.ts that uses getAriaBoolean() to check the aria-busy attribute
  • Role Selector Engine: Added busy option support to role selector engine with proper validation
  • TypeScript Support: Added busy?: boolean property to ByRoleOptions type in locatorUtils.ts
  • Documentation: Added comprehensive documentation for the busy option 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-busy attribute are treated as busy=false (following ARIA specification)
  • Elements with aria-busy="true" are treated as busy=true
  • Elements with aria-busy="false" are treated as busy=false
  • The busy attribute 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-busy attribute
  • ✅ 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.

markmur avatar Jun 09 '25 09:06 markmur

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.

github-actions[bot] avatar Jun 09 '25 10:06 github-actions[bot]

@microsoft-github-policy-service agree

markmur avatar Jun 09 '25 10:06 markmur

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.

Skn0tt avatar Jun 23 '25 09:06 Skn0tt

Sounds good, thanks @Skn0tt 👍

markmur avatar Jun 23 '25 12:06 markmur

@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!

dgozman avatar Jul 02 '25 07:07 dgozman