Skip to content

Conversation

@joanlopez
Copy link
Contributor

@joanlopez joanlopez commented Aug 27, 2025

What?

It adds the mapping for all the getBy* methods for the frame API.

Why?

Because we have already implemented all those methods, and we want to expose them as a way to increase our compatibility with Playwright, as described in #5037.

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 #5037

@joanlopez joanlopez self-assigned this Aug 27, 2025
@joanlopez joanlopez requested a review from a team as a code owner August 27, 2025 06:19
@joanlopez joanlopez added area: browser browser: playwright related to Playwright compatibility labels Aug 27, 2025
@joanlopez joanlopez requested review from AgnesToulet and ankur22 and removed request for a team August 27, 2025 06:19
@joanlopez joanlopez changed the title Implement frame.getBy* Implement the frame.getBy* methods Aug 27, 2025
@joanlopez joanlopez added the documentation-needed A PR which will need a separate PR for documentation label 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.

Woohoo! Nice and easy 😄

I think we should test the change still, 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 frame 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 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 frame instead of page.

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

@joanlopez
Copy link
Contributor Author

Woohoo! Nice and easy 😄

...
...

Thanks @ankur22! 🫶

--
What do you think about what I did in bcb22e6?

What I like about this approach is that hopefully later it will be pretty easy to adjust it to #5106, with an empty or equivalent locator that make existing test cases still applicable.

Beyond that, the only other approach I could think of is directly testing the JS surface, but I see we don't have tests like that neither for page.getBy*, so I'd consider it out of the scope of this but rather a nice to have, eventually.

@joanlopez joanlopez requested a review from ankur22 August 27, 2025 10:29
}

for implName, impl := range getByRoleImplementations {
t.Run(implName, func(t *testing.T) { //nolint:paralleltest
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm intentionally not calling t.Parallel(), as I think others suggested to not use the same browser instance for parallel tests (the reason why I refactored the TestGetByRole* to follow the same pattern as the other tests in this file).

Instead, I only use t.Run as a syntatic way of running the same test code that calls the function and does some assertions over both implementations, on the same instance, which must be fine, but not in parallel.

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.

Thanks for the changes! I like how you incorporated the frame into the existing tests 👍 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!

Comment on lines 432 to 448
tb := newTestBrowser(t, withFileServer())
p := tb.NewPage(nil)
opts := &common.FrameGotoOptions{
Timeout: common.DefaultTimeout,
}
_, err := p.Goto(
tb.staticURL("get_by_role_implicit.html"),
opts,
)
require.NoError(t, err)
require.Equal(t, tt.expected, c)

if tt.expectedText != "" {
text, _, err := l.TextContent(sobek.Undefined())
require.NoError(t, err)
require.Equal(t, tt.expectedText, text)
getByRoleImplementations := map[string]interface {
GetByRole(role string, opts *common.GetByRoleOptions) *common.Locator
}{
"page": p,
"frame": p.MainFrame(),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What about putting these lines in a function? I feel like it's repeated a lot in this test file (at least for the GetByRole function which has a lot of tests).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, good idea! What do you think about 353a197?

@joanlopez joanlopez dismissed stale reviews from AgnesToulet and ankur22 via 353a197 August 28, 2025 10:47
@joanlopez joanlopez merged commit 55562fd into master Sep 1, 2025
37 checks passed
@joanlopez joanlopez deleted the frame-getBy branch September 1, 2025 09:05
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 frame.getBy*

3 participants