-
Notifications
You must be signed in to change notification settings - Fork 1.4k
browser: implement locator.pressSequentially() #5241
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
base: master
Are you sure you want to change the base?
browser: implement locator.pressSequentially() #5241
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing! Very much appreciated! 🙇
I've left a couple of comments that need to be addressed before we can merge this in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution 🙇 LGTM overall. There are some minor adjustments we need to make. We should fix the tests and reduce duplication (see the linter error).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking into considerations the changes we've asked for. I've left a couple more comments that should be addressed, but we're on the home stretch 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall. One more small thing to do.
We should also fix the conflicts with the master
branch.
897ee46
to
97d4f44
Compare
@rajan2345 There are linter and test fixes we need to make. You can run these checks locally using |
Thanks for the feedback, @inancgumus. I updated the branch and resolved the linter/test problems. All set for another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates. Some minor suggestions.
{ | ||
"PressSequentiallyTextarea", func(_ *testBrowser, p *common.Page) { | ||
lo := p.Locator("textarea", nil) | ||
require.NoError(t, lo.Clear(common.NewFrameFillOptions(lo.Timeout()))) | ||
|
||
opts := common.NewFramePressOptions(lo.Timeout()) | ||
require.NoError(t, lo.PressSequentially("some text", opts)) | ||
|
||
value, err := p.InputValue("textarea", common.NewFrameInputValueOptions(p.MainFrame().Timeout())) | ||
require.NoError(t, err) | ||
require.Equal(t, "some text", value) | ||
}, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we remove this test? Is it no longer required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bringing this up!
I removed that test because it would sometimes fail, and I thought it was just unreliable, and the testing for word only in place a sentence would work.
I checked the original Playwright implementation again and noticed they specifically test strings with spaces, so I realized it was important to get this right. The failure was occurring because the loop was sending keystrokes much faster than the browser could handle—a classic race condition.
My original design aimed to make it fast, thinking each keypress would fully complete before the next one started.
The fix involved moving the SlowMo pause inside the loop, giving the browser a moment to catch up after each character, and now the function works reliably and maybe the tests will pass. Thanks again!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation ❤️ Did you try restoring this test with your new fixes?
Implements locator.pressSequentially() to type text character by character, simulating real keyboard input. This is useful for testing features like autocomplete, input validation, and character counters that require gradual typing. Fixes grafana#5038
Co-authored-by: Inanc Gumus <[email protected]>
- Add PressSequentially to locatorAPI interface in mapping_test.go - Removed the PressSequentaillyTextArea as it was not needed - Ensures proper handling of spaces and multi-byte characters
Co-authored-by: Inanc Gumus <[email protected]>
Co-authored-by: Inanc Gumus <[email protected]>
c902e86
to
c250446
Compare
What?
Implements
locator.pressSequentially()
to type text character by character, simulating real keyboard input. This is useful for testing features like autocomplete, input validation, and character counters that require gradual typing.Why?
This feature enables k6 users to test scenarios that require real keyboard events for each character, which
locator.fill()
doesn't provide. It's particularly useful when migrating from Playwright to k6, as this is a commonly used Playwright API that k6 currently lacks.Fixes #5038
Checklist
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.
Implementation Details
FramePressOptions
(which already has thedelay
field from Playwright)frame.press()
for each character to fire proper keyboard eventsTest Coverage
Related PR(s)/Issue(s)
Related to issue #4934 (Reduce friction in migrating Playwright scripts to k6)
Closes #5038
Thank you