Skip to content

Commit f215af1

Browse files
authored
feat(getByRole): add support for aria-busy (microsoft#41269)
1 parent 1360dde commit f215af1

12 files changed

Lines changed: 142 additions & 3 deletions

File tree

‎docs/src/api/class-frame.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,8 @@ Attribute name to get the value for.
10411041

10421042
### option: Frame.getByRole.description = %%-locator-get-by-role-option-description-%%
10431043

1044+
### option: Frame.getByRole.busy = %%-locator-get-by-role-option-busy-%%
1045+
10441046
## method: Frame.getByTestId
10451047
* since: v1.27
10461048
- returns: <[Locator]>

‎docs/src/api/class-framelocator.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ in that iframe.
144144

145145
### option: FrameLocator.getByRole.description = %%-locator-get-by-role-option-description-%%
146146

147+
### option: FrameLocator.getByRole.busy = %%-locator-get-by-role-option-busy-%%
148+
147149
## method: FrameLocator.getByTestId
148150
* since: v1.27
149151
- returns: <[Locator]>

‎docs/src/api/class-locator.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,8 @@ Attribute name to get the value for.
14441444

14451445
### option: Locator.getByRole.description = %%-locator-get-by-role-option-description-%%
14461446

1447+
### option: Locator.getByRole.busy = %%-locator-get-by-role-option-busy-%%
1448+
14471449
## method: Locator.getByTestId
14481450
* since: v1.27
14491451
- returns: <[Locator]>

‎docs/src/api/class-page.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,6 +2282,8 @@ Attribute name to get the value for.
22822282

22832283
### option: Page.getByRole.description = %%-locator-get-by-role-option-description-%%
22842284

2285+
### option: Page.getByRole.busy = %%-locator-get-by-role-option-busy-%%
2286+
22852287
## method: Page.getByTestId
22862288
* since: v1.27
22872289
- returns: <[Locator]>

‎docs/src/api/params.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,14 @@ Whether to find an exact match: case-sensitive and whole-string. Default to fals
13841384

13851385
Required aria role.
13861386

1387+
## locator-get-by-role-option-busy
1388+
* since: v1.61
1389+
- `busy` <[boolean]>
1390+
1391+
An attribute that is usually set by `aria-busy`.
1392+
1393+
Learn more about [`aria-busy`](https://www.w3.org/TR/wai-aria-1.2/#aria-busy).
1394+
13871395
## locator-get-by-role-option-checked
13881396
* since: v1.27
13891397
- `checked` <[boolean]>

‎packages/injected/src/roleSelectorEngine.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { parseAttributeSelector } from '@isomorphic/selectorParser';
1818
import { normalizeWhiteSpace } from '@isomorphic/stringUtils';
1919

20-
import { beginAriaCaches, endAriaCaches, getAriaChecked, getAriaDisabled, getAriaExpanded, getAriaLevel, getAriaPressed, getAriaRole, getAriaSelected, getElementAccessibleDescription, getElementAccessibleName, isElementHiddenForAria, kAriaCheckedRoles, kAriaExpandedRoles, kAriaLevelRoles, kAriaPressedRoles, kAriaSelectedRoles } from './roleUtils';
20+
import { beginAriaCaches, endAriaCaches, getAriaBusy, getAriaChecked, getAriaDisabled, getAriaExpanded, getAriaLevel, getAriaPressed, getAriaRole, getAriaSelected, getElementAccessibleDescription, getElementAccessibleName, isElementHiddenForAria, kAriaCheckedRoles, kAriaExpandedRoles, kAriaLevelRoles, kAriaPressedRoles, kAriaSelectedRoles } from './roleUtils';
2121
import { matchesAttributePart } from './selectorUtils';
2222

2323
import type { AttributeSelectorOperator, AttributeSelectorPart } from '@isomorphic/selectorParser';
@@ -37,10 +37,11 @@ type RoleEngineOptions = {
3737
expanded?: boolean;
3838
level?: number;
3939
disabled?: boolean;
40+
busy?: boolean;
4041
includeHidden?: boolean;
4142
};
4243

43-
const kSupportedAttributes = ['selected', 'checked', 'pressed', 'expanded', 'level', 'disabled', 'name', 'description', 'include-hidden'];
44+
const kSupportedAttributes = ['selected', 'checked', 'pressed', 'expanded', 'level', 'disabled', 'busy', 'name', 'description', 'include-hidden'];
4445
kSupportedAttributes.sort();
4546

4647
function validateSupportedRole(attr: string, roles: string[], role: string) {
@@ -106,6 +107,12 @@ function validateAttributes(attrs: AttributeSelectorPart[], role: string): RoleE
106107
options.disabled = attr.op === '<truthy>' ? true : attr.value;
107108
break;
108109
}
110+
case 'busy': {
111+
validateSupportedValues(attr, [true, false]);
112+
validateSupportedOp(attr, ['<truthy>', '=']);
113+
options.busy = attr.op === '<truthy>' ? true : attr.value;
114+
break;
115+
}
109116
case 'name': {
110117
if (attr.op === '<truthy>')
111118
throw new Error(`"name" attribute must have a value`);
@@ -157,6 +164,8 @@ function queryRole(scope: SelectorRoot, options: RoleEngineOptions, internal: bo
157164
return;
158165
if (options.disabled !== undefined && getAriaDisabled(element) !== options.disabled)
159166
return;
167+
if (options.busy !== undefined && getAriaBusy(element) !== options.busy)
168+
return;
160169
if (!options.includeHidden) {
161170
const isHidden = isElementHiddenForAria(element);
162171
if (isHidden)

‎packages/injected/src/roleUtils.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,12 @@ function hasExplicitAriaDisabled(element: Element | undefined, isAncestor = fals
11541154
return false;
11551155
}
11561156

1157+
export function getAriaBusy(element: Element): boolean {
1158+
// https://www.w3.org/TR/wai-aria-1.2/#aria-busy
1159+
// aria-busy is a global state with a default value of "false".
1160+
return getAriaBoolean(element.getAttribute('aria-busy')) === true;
1161+
}
1162+
11571163
function getAccessibleNameFromAssociatedLabels(labels: Iterable<HTMLLabelElement>, options: AccessibleNameOptions) {
11581164
return [...labels].map(label => getTextAlternativeInternal(label, {
11591165
...options,

‎packages/isomorphic/locatorUtils.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { escapeForAttributeSelector, escapeForTextSelector } from './stringUtils';
1818

1919
export type ByRoleOptions = {
20+
busy?: boolean;
2021
checked?: boolean;
2122
description?: string | RegExp;
2223
disabled?: boolean;
@@ -86,5 +87,7 @@ export function getByRoleSelector(role: string, options: ByRoleOptions = {}): st
8687
props.push(['description', escapeForAttributeSelector(options.description, !!options.exact)]);
8788
if (options.pressed !== undefined)
8889
props.push(['pressed', String(options.pressed)]);
90+
if (options.busy !== undefined)
91+
props.push(['busy', String(options.busy)]);
8992
return `internal:role=${role}${props.map(([n, v]) => `[${n}=${v}]`).join('')}`;
9093
}

‎packages/playwright-client/types/types.d.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,6 +2949,13 @@ export interface Page {
29492949
* @param options
29502950
*/
29512951
getByRole(role: "alert"|"alertdialog"|"application"|"article"|"banner"|"blockquote"|"button"|"caption"|"cell"|"checkbox"|"code"|"columnheader"|"combobox"|"complementary"|"contentinfo"|"definition"|"deletion"|"dialog"|"directory"|"document"|"emphasis"|"feed"|"figure"|"form"|"generic"|"grid"|"gridcell"|"group"|"heading"|"img"|"insertion"|"link"|"list"|"listbox"|"listitem"|"log"|"main"|"marquee"|"math"|"meter"|"menu"|"menubar"|"menuitem"|"menuitemcheckbox"|"menuitemradio"|"navigation"|"none"|"note"|"option"|"paragraph"|"presentation"|"progressbar"|"radio"|"radiogroup"|"region"|"row"|"rowgroup"|"rowheader"|"scrollbar"|"search"|"searchbox"|"separator"|"slider"|"spinbutton"|"status"|"strong"|"subscript"|"superscript"|"switch"|"tab"|"table"|"tablist"|"tabpanel"|"term"|"textbox"|"time"|"timer"|"toolbar"|"tooltip"|"tree"|"treegrid"|"treeitem", options?: {
2952+
/**
2953+
* An attribute that is usually set by `aria-busy`.
2954+
*
2955+
* Learn more about [`aria-busy`](https://www.w3.org/TR/wai-aria-1.2/#aria-busy).
2956+
*/
2957+
busy?: boolean;
2958+
29522959
/**
29532960
* An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls.
29542961
*
@@ -6848,6 +6855,13 @@ export interface Frame {
68486855
* @param options
68496856
*/
68506857
getByRole(role: "alert"|"alertdialog"|"application"|"article"|"banner"|"blockquote"|"button"|"caption"|"cell"|"checkbox"|"code"|"columnheader"|"combobox"|"complementary"|"contentinfo"|"definition"|"deletion"|"dialog"|"directory"|"document"|"emphasis"|"feed"|"figure"|"form"|"generic"|"grid"|"gridcell"|"group"|"heading"|"img"|"insertion"|"link"|"list"|"listbox"|"listitem"|"log"|"main"|"marquee"|"math"|"meter"|"menu"|"menubar"|"menuitem"|"menuitemcheckbox"|"menuitemradio"|"navigation"|"none"|"note"|"option"|"paragraph"|"presentation"|"progressbar"|"radio"|"radiogroup"|"region"|"row"|"rowgroup"|"rowheader"|"scrollbar"|"search"|"searchbox"|"separator"|"slider"|"spinbutton"|"status"|"strong"|"subscript"|"superscript"|"switch"|"tab"|"table"|"tablist"|"tabpanel"|"term"|"textbox"|"time"|"timer"|"toolbar"|"tooltip"|"tree"|"treegrid"|"treeitem", options?: {
6858+
/**
6859+
* An attribute that is usually set by `aria-busy`.
6860+
*
6861+
* Learn more about [`aria-busy`](https://www.w3.org/TR/wai-aria-1.2/#aria-busy).
6862+
*/
6863+
busy?: boolean;
6864+
68516865
/**
68526866
* An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls.
68536867
*
@@ -14137,6 +14151,13 @@ export interface Locator {
1413714151
* @param options
1413814152
*/
1413914153
getByRole(role: "alert"|"alertdialog"|"application"|"article"|"banner"|"blockquote"|"button"|"caption"|"cell"|"checkbox"|"code"|"columnheader"|"combobox"|"complementary"|"contentinfo"|"definition"|"deletion"|"dialog"|"directory"|"document"|"emphasis"|"feed"|"figure"|"form"|"generic"|"grid"|"gridcell"|"group"|"heading"|"img"|"insertion"|"link"|"list"|"listbox"|"listitem"|"log"|"main"|"marquee"|"math"|"meter"|"menu"|"menubar"|"menuitem"|"menuitemcheckbox"|"menuitemradio"|"navigation"|"none"|"note"|"option"|"paragraph"|"presentation"|"progressbar"|"radio"|"radiogroup"|"region"|"row"|"rowgroup"|"rowheader"|"scrollbar"|"search"|"searchbox"|"separator"|"slider"|"spinbutton"|"status"|"strong"|"subscript"|"superscript"|"switch"|"tab"|"table"|"tablist"|"tabpanel"|"term"|"textbox"|"time"|"timer"|"toolbar"|"tooltip"|"tree"|"treegrid"|"treeitem", options?: {
14154+
/**
14155+
* An attribute that is usually set by `aria-busy`.
14156+
*
14157+
* Learn more about [`aria-busy`](https://www.w3.org/TR/wai-aria-1.2/#aria-busy).
14158+
*/
14159+
busy?: boolean;
14160+
1414014161
/**
1414114162
* An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls.
1414214163
*
@@ -19602,6 +19623,13 @@ export interface FrameLocator {
1960219623
* @param options
1960319624
*/
1960419625
getByRole(role: "alert"|"alertdialog"|"application"|"article"|"banner"|"blockquote"|"button"|"caption"|"cell"|"checkbox"|"code"|"columnheader"|"combobox"|"complementary"|"contentinfo"|"definition"|"deletion"|"dialog"|"directory"|"document"|"emphasis"|"feed"|"figure"|"form"|"generic"|"grid"|"gridcell"|"group"|"heading"|"img"|"insertion"|"link"|"list"|"listbox"|"listitem"|"log"|"main"|"marquee"|"math"|"meter"|"menu"|"menubar"|"menuitem"|"menuitemcheckbox"|"menuitemradio"|"navigation"|"none"|"note"|"option"|"paragraph"|"presentation"|"progressbar"|"radio"|"radiogroup"|"region"|"row"|"rowgroup"|"rowheader"|"scrollbar"|"search"|"searchbox"|"separator"|"slider"|"spinbutton"|"status"|"strong"|"subscript"|"superscript"|"switch"|"tab"|"table"|"tablist"|"tabpanel"|"term"|"textbox"|"time"|"timer"|"toolbar"|"tooltip"|"tree"|"treegrid"|"treeitem", options?: {
19626+
/**
19627+
* An attribute that is usually set by `aria-busy`.
19628+
*
19629+
* Learn more about [`aria-busy`](https://www.w3.org/TR/wai-aria-1.2/#aria-busy).
19630+
*/
19631+
busy?: boolean;
19632+
1960519633
/**
1960619634
* An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls.
1960719635
*

‎packages/playwright-core/types/types.d.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,6 +2949,13 @@ export interface Page {
29492949
* @param options
29502950
*/
29512951
getByRole(role: "alert"|"alertdialog"|"application"|"article"|"banner"|"blockquote"|"button"|"caption"|"cell"|"checkbox"|"code"|"columnheader"|"combobox"|"complementary"|"contentinfo"|"definition"|"deletion"|"dialog"|"directory"|"document"|"emphasis"|"feed"|"figure"|"form"|"generic"|"grid"|"gridcell"|"group"|"heading"|"img"|"insertion"|"link"|"list"|"listbox"|"listitem"|"log"|"main"|"marquee"|"math"|"meter"|"menu"|"menubar"|"menuitem"|"menuitemcheckbox"|"menuitemradio"|"navigation"|"none"|"note"|"option"|"paragraph"|"presentation"|"progressbar"|"radio"|"radiogroup"|"region"|"row"|"rowgroup"|"rowheader"|"scrollbar"|"search"|"searchbox"|"separator"|"slider"|"spinbutton"|"status"|"strong"|"subscript"|"superscript"|"switch"|"tab"|"table"|"tablist"|"tabpanel"|"term"|"textbox"|"time"|"timer"|"toolbar"|"tooltip"|"tree"|"treegrid"|"treeitem", options?: {
2952+
/**
2953+
* An attribute that is usually set by `aria-busy`.
2954+
*
2955+
* Learn more about [`aria-busy`](https://www.w3.org/TR/wai-aria-1.2/#aria-busy).
2956+
*/
2957+
busy?: boolean;
2958+
29522959
/**
29532960
* An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls.
29542961
*
@@ -6848,6 +6855,13 @@ export interface Frame {
68486855
* @param options
68496856
*/
68506857
getByRole(role: "alert"|"alertdialog"|"application"|"article"|"banner"|"blockquote"|"button"|"caption"|"cell"|"checkbox"|"code"|"columnheader"|"combobox"|"complementary"|"contentinfo"|"definition"|"deletion"|"dialog"|"directory"|"document"|"emphasis"|"feed"|"figure"|"form"|"generic"|"grid"|"gridcell"|"group"|"heading"|"img"|"insertion"|"link"|"list"|"listbox"|"listitem"|"log"|"main"|"marquee"|"math"|"meter"|"menu"|"menubar"|"menuitem"|"menuitemcheckbox"|"menuitemradio"|"navigation"|"none"|"note"|"option"|"paragraph"|"presentation"|"progressbar"|"radio"|"radiogroup"|"region"|"row"|"rowgroup"|"rowheader"|"scrollbar"|"search"|"searchbox"|"separator"|"slider"|"spinbutton"|"status"|"strong"|"subscript"|"superscript"|"switch"|"tab"|"table"|"tablist"|"tabpanel"|"term"|"textbox"|"time"|"timer"|"toolbar"|"tooltip"|"tree"|"treegrid"|"treeitem", options?: {
6858+
/**
6859+
* An attribute that is usually set by `aria-busy`.
6860+
*
6861+
* Learn more about [`aria-busy`](https://www.w3.org/TR/wai-aria-1.2/#aria-busy).
6862+
*/
6863+
busy?: boolean;
6864+
68516865
/**
68526866
* An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls.
68536867
*
@@ -14137,6 +14151,13 @@ export interface Locator {
1413714151
* @param options
1413814152
*/
1413914153
getByRole(role: "alert"|"alertdialog"|"application"|"article"|"banner"|"blockquote"|"button"|"caption"|"cell"|"checkbox"|"code"|"columnheader"|"combobox"|"complementary"|"contentinfo"|"definition"|"deletion"|"dialog"|"directory"|"document"|"emphasis"|"feed"|"figure"|"form"|"generic"|"grid"|"gridcell"|"group"|"heading"|"img"|"insertion"|"link"|"list"|"listbox"|"listitem"|"log"|"main"|"marquee"|"math"|"meter"|"menu"|"menubar"|"menuitem"|"menuitemcheckbox"|"menuitemradio"|"navigation"|"none"|"note"|"option"|"paragraph"|"presentation"|"progressbar"|"radio"|"radiogroup"|"region"|"row"|"rowgroup"|"rowheader"|"scrollbar"|"search"|"searchbox"|"separator"|"slider"|"spinbutton"|"status"|"strong"|"subscript"|"superscript"|"switch"|"tab"|"table"|"tablist"|"tabpanel"|"term"|"textbox"|"time"|"timer"|"toolbar"|"tooltip"|"tree"|"treegrid"|"treeitem", options?: {
14154+
/**
14155+
* An attribute that is usually set by `aria-busy`.
14156+
*
14157+
* Learn more about [`aria-busy`](https://www.w3.org/TR/wai-aria-1.2/#aria-busy).
14158+
*/
14159+
busy?: boolean;
14160+
1414014161
/**
1414114162
* An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls.
1414214163
*
@@ -19602,6 +19623,13 @@ export interface FrameLocator {
1960219623
* @param options
1960319624
*/
1960419625
getByRole(role: "alert"|"alertdialog"|"application"|"article"|"banner"|"blockquote"|"button"|"caption"|"cell"|"checkbox"|"code"|"columnheader"|"combobox"|"complementary"|"contentinfo"|"definition"|"deletion"|"dialog"|"directory"|"document"|"emphasis"|"feed"|"figure"|"form"|"generic"|"grid"|"gridcell"|"group"|"heading"|"img"|"insertion"|"link"|"list"|"listbox"|"listitem"|"log"|"main"|"marquee"|"math"|"meter"|"menu"|"menubar"|"menuitem"|"menuitemcheckbox"|"menuitemradio"|"navigation"|"none"|"note"|"option"|"paragraph"|"presentation"|"progressbar"|"radio"|"radiogroup"|"region"|"row"|"rowgroup"|"rowheader"|"scrollbar"|"search"|"searchbox"|"separator"|"slider"|"spinbutton"|"status"|"strong"|"subscript"|"superscript"|"switch"|"tab"|"table"|"tablist"|"tabpanel"|"term"|"textbox"|"time"|"timer"|"toolbar"|"tooltip"|"tree"|"treegrid"|"treeitem", options?: {
19626+
/**
19627+
* An attribute that is usually set by `aria-busy`.
19628+
*
19629+
* Learn more about [`aria-busy`](https://www.w3.org/TR/wai-aria-1.2/#aria-busy).
19630+
*/
19631+
busy?: boolean;
19632+
1960519633
/**
1960619634
* An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls.
1960719635
*

0 commit comments

Comments
 (0)