Skip to content

[Feature] extend Locator API with helper methods #16785

Description

@gajus

As an example, I would like to introduce findByRole method that is equivalent to:

page.locator(
  `role=${role}[name="${name}"]`
)

I have figured out how to add this to Page object,

#1604 (comment)

This allows me to write code like:

await page.findByRole('link', 'Services').click();

However, this breaks when chaining Locator instances, e.g.

await page
  .locator('role=dialog')
-  .locator('role=link[name="Create A Service"]')
+  .findByRole('link', 'Create A Service')
  .click();

The above is throwing an error since .locator('role=dialog') is returning an instance of a Locator that is not aware of findByRole.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions