Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
5 of 6 tasks
xeger opened this issue Dec 2, 2024 · 4 comments
Labels
p2-nice-to-have Not breaking anything but nice to have (priority) pr welcome

Comments

@xeger
Copy link
Contributor

xeger commented Dec 2, 2024

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

@sheremet-va sheremet-va added p2-nice-to-have Not breaking anything but nice to have (priority) pr welcome and removed enhancement: pending triage labels Dec 9, 2024
@sheremet-va
Copy link
Member

sheremet-va commented Dec 9, 2024

The initial implementation just has all the important ones. We are open to having most of the locators implemented, except the public locator function itself.

They should be really easy to implement because we already use Playwright selectors.

@xeger
Copy link
Contributor Author

xeger commented Dec 27, 2024

I've added support for nth; let me know what you think @sheremet-va:
#7137

@xeger
Copy link
Contributor Author

xeger commented Dec 27, 2024

On the topic of which other locator methods to support, .filter looks extremely useful as it's recommended to solve a class of problem i.e. find parent element without relying on xpath.

I'd want to do filter in a separate PR.

What about and / or? Need to look into their semantics more to see how useful they'd be to me.

@sheremet-va
Copy link
Member

sheremet-va commented Jan 3, 2025

On the topic of which other locator methods to support, .filter looks extremely useful as it's recommended to solve a class of problem i.e. find parent element without relying on xpath.

I'd want to do filter in a separate PR.

What about and / or? Need to look into their semantics more to see how useful they'd be to me.

We can support all of them. The engine already does, we just need a wrapper that constructs the selector. The only thing I want to avoid is exposing the locator directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority) pr welcome
Projects
None yet
Development

No branches or pull requests

2 participants