Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Indeterminate state test for checkboxes #33946

Open
Bilge opened this issue Dec 11, 2024 · 4 comments · May be fixed by #34269
Open

[Feature]: Indeterminate state test for checkboxes #33946

Bilge opened this issue Dec 11, 2024 · 4 comments · May be fixed by #34269

Comments

@Bilge
Copy link

Bilge commented Dec 11, 2024

🚀 Feature Request

Playwright (incorrectly) assumes checkboxes are binary; they are not. The default checkbox may specify the indeterminate state, in which it is neither checked nor unchecked. Moreover, aria-checked may specify mixed (in addition to true or false). The Playwright API seems completely ignorant of the third state, such that locator.toBeChecked() cannot test for it and locator.setChecked() cannot set it.

It is important to have an ARIA-compatible test for this, since there is no guarantee custom control will implement the mechanism using the indeterminate property; the only requirement is that they set aria-checked to mixed.

Example

expect(check).toBeChecked({checked: 'indeterminate'});
OR
expect(check).toBeChecked({checked: 'mixed'});
OR
expect(check).toBeChecked({indeterminate: true});
OR
expect(check).toBeIndeterminate();

Motivation

It is difficult to test the state of a tri-state checkbox without an ARIA-compatible API.

@yury-s
Copy link
Member

yury-s commented Dec 11, 2024

This was extensively discussed in #20190, see the last comment in particular for the overview of differences in browser implementations. We decided to stay on the side of treating indeterminate as checked since #20834.

@Bilge
Copy link
Author

Bilge commented Dec 11, 2024

It is absolutely wrong to consider indeterminate as checked. That's like saying, at a junction where you can turn left, right or go straight ahead, we just always treat left as right.

@pavelfeldman
Copy link
Member

pavelfeldman commented Jan 6, 2025

@Bilge as a workaround, you can use this:

await expect(page.locator('input')).toMatchAriaSnapshot('- checkbox [checked=mixed]');

@tphillips-ict
Copy link

tphillips-ict commented Jan 7, 2025

It is absolutely wrong to consider indeterminate as checked. That's like saying, at a junction where you can turn left, right or go straight ahead, we just always treat left as right.

Well, not really. It's more like saying "At an intersection where you can go left or right, and there's a dirt road that goes straight ahead, we treat left as left, right and the dirt road as right"
Mixed is not as often used and as mentioned is inconsistent between browsers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants