Skip to content

Conversation

joanlopez
Copy link
Contributor

@joanlopez joanlopez commented Aug 27, 2025

What?

It implements all the getBy* methods for the locator API.

Why?

Because we have already implemented all those methods for page and frame, and we want to implement them as well for locator as a way to increase our compatibility with Playwright, as described in #5029.

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Checklist: Documentation (only for k6 maintainers and if relevant)

Please do not merge this PR until the following items are filled out.

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

Closes #5029

@joanlopez joanlopez self-assigned this Aug 27, 2025
@joanlopez joanlopez requested a review from a team as a code owner August 27, 2025 07:25
@joanlopez joanlopez requested review from AgnesToulet and ankur22 and removed request for a team August 27, 2025 07:25
@joanlopez joanlopez added documentation-needed A PR which will need a separate PR for documentation area: browser browser: playwright related to Playwright compatibility labels Aug 27, 2025
@joanlopez joanlopez added this to the v1.3.0 milestone Aug 27, 2025
ankur22
ankur22 previously approved these changes Aug 27, 2025
Copy link
Contributor

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work 🙇

I think we should test the change, even though most of the implementation is already covered in the get_by_test.go file.

It could just be a subset of those tests translated to work with locator instead of page, so for each it could just be:

  • a happy path test that works with the required fields;
  • a happy path test that works with an option;
  • a happy path using locator chaining e.g. page.locator(#table).getByText('Hello world').click();.
  • a failing test to ensure we are testing null values for the required fields.

It might just be a case of copying the whole file and using locator instead of page.

Happy for you to merge this PR in and work on the test in another PR if you wish.

ankur22
ankur22 previously approved these changes Aug 27, 2025
Copy link
Contributor

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

AgnesToulet
AgnesToulet previously approved these changes Aug 28, 2025
Copy link
Contributor

@AgnesToulet AgnesToulet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Agree that these should be tested though but I guess you are waiting for #5105 to be merged to build upon your changes there.

@joanlopez
Copy link
Contributor Author

LGTM! Agree that these should be tested though but I guess you are waiting for #5105 to be merged to build upon your changes there.

Yeah, exactly! I'm awaiting for the other PR to be merged to try to get locator related tests into this.

@joanlopez joanlopez dismissed stale reviews from ankur22 and AgnesToulet via 88018be September 1, 2025 10:34
@joanlopez
Copy link
Contributor Author

Hi @AgnesToulet, @ankur22,

I've reused the changes introduced in #5105 to also test the Locator API mappings introduced in this changeset, on the HTML doc's root (:root), as discussed and suggested. So, I guess that, hopefully, now it's ready to go! 🤞🏻

Thanks for your support! 🙌🏻

ankur22
ankur22 previously approved these changes Sep 1, 2025
Copy link
Contributor

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 😄

{role: "directory", expected: 1, expectedText: "Directory"},
// The original document plus the one within the html <section>
{role: "document", expected: 2, expectedText: ""},
{role: "document", expected: 1, expectedText: ""},
Copy link
Contributor Author

@joanlopez joanlopez Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dear reviewer, take a look at the following discussion #5106 (comment) to get more context why this changed is needed. Thanks! 🙇🏻

})
}

// We test the 'document' role independently, because the expectations
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dear reviewer, take a look at the following discussion #5106 (comment) to get more context why this changed is needed. Thanks! 🙇🏻

@joanlopez joanlopez merged commit eecfb6b into master Sep 4, 2025
43 of 44 checks passed
@joanlopez joanlopez deleted the locator-getBy branch September 4, 2025 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: browser browser: playwright related to Playwright compatibility documentation-needed A PR which will need a separate PR for documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement locator.getBy*

3 participants