Skip to content

Expand locators implementation to support common chaining cases for better parity with Playwright locators #7008

@xeger

Description

@xeger

Clear and concise description of the problem

Playwright supports an nth() method on its Locator which derives a new locator targeting a specific index in a multi-element set.

We can accomplish something similar in vitest using expect.poll of course:

await expect.poll( ()=> page.getByRole('button').elements()[3] ).toBeInTheDocument();

But this can get annoying if we want to perform an interaction e.g. click on the element -- we need to wrap the element in a locator again.

Suggested solution

Alternative

As mentioned, there is always some way to accomplish what we need using expect.poll, but the Playwright idioms of nth, and, or etc are highly productive and readable in comparison.

Additional context

My testing team is interested in this feature and we may be willing to try implementing it, but I wanted to check on the maintainers' opinions first to make sure this is a reasonable direction for ivya + vitest to move in.

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions