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

feat: Implement Locator.nth() #7137

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

xeger
Copy link

@xeger xeger commented Dec 27, 2024

Description

This adds more parity with Playwright locators as discussed in #7008.

Compared to elements()[n], the nth modifier promotes easier-to-debug tests by throwing an obvious error message instead of letting a matcher fail on undefined or allowing the caller to try and call some additional locator method.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Dec 27, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 5eb90d8
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/6770426295919c000864e2f7
😎 Deploy Preview https://deploy-preview-7137--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@xeger xeger requested a review from sheremet-va December 27, 2024 19:21
@xeger
Copy link
Author

xeger commented Dec 28, 2024

The exception message is 100% accurate now that I am using the nth engine instead of reinventing ivya/playwright 😬 .

I feel a bit bad because I am writing selector notation by hand, using string interpolation, whereas the other methods are importing from ivya locatorUtils e.g. getByRoleSelector -- so, other methods don't pollute vitest/browser with selector notation. However, ivya provides no helper method for nth engine, nor does playwright main at this time, so it's probably fine for now.

I also added first / last which are sugar, but useful. I think I'm happy with this PR. There are other useful locator methods e.g. and / or but I want to gain more experience actually using vitest + playwright to write tests before I blindly add features. If you know of any high-value or popular missing features, LMK and I will work on them in a separate PR.

@xeger xeger requested a review from sheremet-va December 28, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants