k6-docs
k6-docs copied to clipboard
Choosing `locator` methods
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.