-
Notifications
You must be signed in to change notification settings - Fork 43
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.
Nicely done, I just think we should move it to press()
instead.
And re: the Shift+b
behavior, I don't think Playwright makes sense in that case. Shift+b
or Shift+B
should produce B
in both cases. A lowercase b
can be typed without Shift
. It's fine if we diverge with them to improve things. :)
I'm mostly OK with what you propose @imiric, but here are my two cents. Is diverging PW, in this case, worth it? If I were a tester, I'd at least expect similar behavior. Puppeteers also work with So instead of As I said, I'm also OK with what you proposed. But, I'm not sure whether we're improving things or making people's life harder 😅 |
I wasn't familiar with the
That's still confusing to me. Does the But still, let's confirm what Playwright's behavior is for this as well, and follow that to avoid adding more surprises for users. |
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.
As @imiric also noticed, splitting a given key should be done in press
. down
and up
are only responsible for a single key, and that key can be a modifier as well. For more info: https://github.com/grafana/xk6-browser/pull/326/files#r885768387.
c10d41d
to
e65be16
Compare
I'm unable to get the kb.Press("Shift+KeyA", nil)
kb.Press("Shift+b", nil)
kb.Press("Shift+C", nil)
metaKey := "Control"
if runtime.GOOS == "darwin" {
metaKey = "Meta"
}
kb.Press(metaKey+"+A", nil)
kb.Press("Delete", nil) OR kb.Press("Shift+KeyA", nil)
kb.Press("Shift+b", nil)
kb.Press("Shift+C", nil)
kb.Press("Alt+ArrowLeft", nil)
kb.Press("Delete", nil) This should delete the text that has been written into the input field. To continue to track and resolve this a new ticket has been opened: grafana/k6#4440 |
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.
I'll continue looking into this tomorrow, but it failed on my machine as follows:
--- FAIL: TestPageInputSpecialCharacters (0.68s)
page_test.go:341:
Error Trace: page_test.go:341
Error: Not equal:
expected: "[email protected]"
actual : "test@k^>io"
Diff:
--- Expected
+++ Actual
@@ -1 +1 @@
[email protected]
+test@k^>io
Test: TestPageInputSpecialCharacters
page_test.go:341:
Error Trace: page_test.go:341
Error: Not equal:
expected: "<hello WoRlD \\/>"
actual : "<hello WoRlD |?>"
Diff:
--- Expected
+++ Actual
@@ -1 +1 @@
-<hello WoRlD \/>
+<hello WoRlD |?>
Test: TestPageInputSpecialCharacters
page_test.go:341:
Error Trace: page_test.go:341
Error: Not equal:
expected: "¯\\_(ツ)_/¯"
actual : "¯|_(ツ)_?¯"
Diff:
--- Expected
+++ Actual
@@ -1 +1 @@
-¯\_(ツ)_/¯
+¯|_(ツ)_?¯
Test: TestPageInputSpecialCharacters
Update: CI has reported the failure as well: https://github.com/grafana/xk6-browser/runs/7114936484?check_suite_focus=true
|
||
if err := k.comboPress(key, kbdOpts); err != nil { |
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.
Nit: No need to put an empty line here, but your call :)
common/keyboard.go
Outdated
} | ||
} | ||
|
||
for i := len(kk) - 1; i >= 0; i-- { |
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.
Is there a reason why this is not a range
as the above down
loop?
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.
It's going backwards:
a->b->c
c->b->a
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.
Ah, OK :) It's the same, but what about?
for i := range kk {
// kk[len(kk)-i-1]
}
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.
Yeah sure, nice little trick 🙂
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.
That trick is not intuitive at all IMO. The previous C-style for
was clear and straightforward.
Please let's not point out style issues in reviews (we agreed on this before Ankur joined), unless the reviewer can explain an objective benefit of the change.
No need to change this back now, I don't want to spend more time on this, but just for future reference.
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.
I looked more into this. Here are my new findings.
common/keyboard.go
Outdated
//nolint:gocritic | ||
if string(s) == "+" && ss != "" { | ||
kk = append(kk, ss) | ||
ss = "" |
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.
The linter is right. It's better to convert the if-else chain into a switch.
for _, k := range keys {
switch {
case k == '+' && ss != "":
...
...
And, you can use strings.Builder
to append runes without converting them to string.
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.
Nice, I hadn't realised that it was idiomatic to write them as switch statements. Source: https://go.dev/doc/effective_go#switch
Resolves: #326 (comment) Resolves: #326 (comment) Resolves: #326 (comment) Resolves: #326 (comment)
ca801e7
to
f959cb1
Compare
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.
Nice work 👍 Only the test comment seems like a blocker to me, the others are minor suggestions.
It's strange that meta keys don't seem to work. That's a pretty important issue, but we can tackle it later.
Also, remember to mark the PR "Ready for review" when it's done being a draft.
Some of the integration tests can easily be converted to unit tests which makes running them quicker, as well as making the tests simpler. It also helps group similar tests. Resolves: #326 (comment)
Resolves: #326 (comment) Resolves: #326 (comment) Resolves: #326 (comment) Resolves: #326 (comment)
71ba9f5
to
8735b37
Compare
Some of the integration tests can easily be converted to unit tests which makes running them quicker, as well as making the tests simpler. It also helps group similar tests. Resolves: #326 (comment)
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, nice work 👍
I would just move split()
to common/helpers.go
and its tests to helpers_test.go
. On second thought, it might be a uniquely keyboard helper function, so it makes sense where it is. Up to you.
The CI failures don't seem to be related to these changes, though that TestPageGotoWaitUntilDOMContentLoaded
is a new one I haven't seen before. 😕 Please squash this into a single commit and push it so the tests run again before merging.
799182f
to
c3d4a69
Compare
This change enables the `Shift` to alter the case of letters if the special `Key*` is used (where * is A-z). The shift key is only used when working with certain keyboard methods, and `Type` is not one of them. The change follows the same behaviour as was found in PlayWright. The separator is `+`, so "Shift+KeyA" would be split into "Shift" and "KeyA". Closes: #285
c3d4a69
to
88b910a
Compare
Decided to not move it to the helper file since it feels like it might only be for the keyboard.
Squashed the commits, and the build failed with the usual errors we've seen before. I reran the CI tests and it passed. |
ElementHandle, Page, Locator and Frame all have the Press method. In a recent fix (#326) combo keys with the Shift modifier key was fixed for the Keyboard Press method. The Press methods for the other classes should have worked with combo ley presses, but didn't. This fix will ensure that combo key presses work for all of them. Closes: #521
* Fix press in classes to work with combo keys ElementHandle, Page, Locator and Frame all have the Press method. In a recent fix (#326) combo keys with the Shift modifier key was fixed for the Keyboard Press method. The Press methods for the other classes should have worked with combo ley presses, but didn't. This fix will ensure that combo key presses work for all of them. Closes: #521 * Apply suggestions from code review Co-authored-by: Ivan Mirić <[email protected]> Co-authored-by: Ivan Mirić <[email protected]>
This fixes #285
Shift+X when passed to press() and used in conjunction with down() and up() now will change the casing of the character, as long as the character is in the format
KeyX
. A key press that isx
orX
will ignore the shift modifier key. This fix matches the playwright behaviour.E.g.
The Shift modifier will only change the case of a character if KeyA - KeyZ is used.