Playwright

tags:  test, typescript

Good practices

Usage of getByRole

The recommended path for accessing data of the DOM is using getByRole instead of using old ways to access data like data-test attributes or even using specific ids or class names (like test- prefixes or any other strategy the team has).

An example of accessing an input element in the DOM using getByRole:

await page.getByRole('checkbox', { name: 'Subscribe' }).check();

Using getByRole allows the developer to use the page as an user with assistive technology browsers the application. This way is an early way to find accessibility issues in the application. PlaywrightPlaywright
Good practices

Usage of getByRole

The recommended path for accessing data of the DOM is using getByRole instead of using old ways to access data like data-test attributes or even using specific i...
docs also advises that this doesn't replaces accessibility tests.

References