Skip to content

Choosing locator methods #2087

@ankur22

Description

@ankur22

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions