k6-docs icon indicating copy to clipboard operation
k6-docs copied to clipboard

Choosing `locator` methods

Open ankur22 opened this issue 2 months ago • 0 comments

What

Using generic selectors instead of semantic ones reduces test maintainability e.g.:

const l = page.locator('#some-id');

Solution

Prefer getBy* methods over generic locator() when possible. These APIs are available from page, locator, frame and frameLocator. These usually work with selectors that are more user facing.

Semantic locators are more maintainable and readable. Playwright also recommends their use. Also take a look at the testing library for more details.

ankur22 avatar Oct 01 '25 08:10 ankur22