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

test: Clean up keyboard input API #20563

Merged
merged 3 commits into from
Jun 10, 2024
Merged

Conversation

martinpitt
Copy link
Member

Fixes #20344

@martinpitt martinpitt added the no-test For doc/workflow changes, or experiments which don't need a full CI run, label Jun 7, 2024
@martinpitt
Copy link
Member Author

This is the hard bit. The remaining one is to rename key_press() to input_text(), and dramatically simplify it.

@martinpitt martinpitt removed the no-test For doc/workflow changes, or experiments which don't need a full CI run, label Jun 8, 2024
@martinpitt martinpitt marked this pull request as ready for review June 9, 2024 07:26
@martinpitt martinpitt requested a review from jelly June 9, 2024 07:26
@martinpitt martinpitt force-pushed the test-key branch 2 times, most recently from d12eecf to dd46ce5 Compare June 9, 2024 10:00
jelly
jelly previously approved these changes Jun 10, 2024
Copy link
Member

@jelly jelly left a comment

Choose a reason for hiding this comment

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

This is really cool! I expected that this would impact more of our tests and the reason why I never considered it a reasonable refactor. (Too much churn)

But this new API is nicer and higher level and a bit more explicit with input_text, I like it.

I made two small notes, feel free to address or ignore. Another thing which came to mind is that maybe adding a docstring to the new functions is worth the effort.

"Escape": 27,
"ArrowDown": 40,
"Insert": 45,
}
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, its a bit different from https://github.com/cockpit-project/cockpit-files/blob/main/test/check-application#L47

So it would be nice to add ArrowUp/ArrowLeft/ArrowRight if that is still needed

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what I hinted at in the commit message: c-storage-partitions already uses ArrowLeft and that seems to be fine. I don't see any pattern here yet. But I expect some more fallout from this indeed, we may have to adjust that a bit in the future still.

Copy link
Member Author

Choose a reason for hiding this comment

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

I locally tested this branch against cockpit-project/cockpit-files#543 and it all passed.

b.key_press(chr(37), use_ord=True)
b.key_press(chr(37), use_ord=True)
b.key_press(chr(37), use_ord=True)
b.key("ArrowLeft", 5)
Copy link
Member

Choose a reason for hiding this comment

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

kinda wondering if we want to be more explicity here repeat=5

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

This already helps to clean up some redundant code in TestHostSwitching
and TestMenu, and will help to convert key_press() calls to key().
That makes the code easier to read/understand, and paves the way for
deprecating key_press(). Add a `modifiers` kwarg to it too, as we need
that for at least TestTerminal.

Unfortunately Chromium is a bit buggy and doesn't understand some `key=`
names like "Backspace" or "ArrowDown" in some (but not all!)
circumstances/tests. It works fine for most other, like "Tab", or
(really curiously) "ArrowLeft". Add a workaround by translating these to
`windowsVirtualKeyCode`, as `key_press()` does.
`input_text()` is now solely for plain characters, no control ones or
modifiers. That keeps the implementation very simple and browser independent.

Fixes cockpit-project#20344
@martinpitt
Copy link
Member Author

@jelly Thanks for the review! I already sent a draft PR for files to use this (verified locally), and added docstrings.

@martinpitt martinpitt requested a review from jelly June 10, 2024 05:40
@martinpitt martinpitt merged commit cbe46ee into cockpit-project:main Jun 10, 2024
81 checks passed
@martinpitt martinpitt deleted the test-key branch June 10, 2024 10:11
martinpitt added a commit to martinpitt/cockpit-podman that referenced this pull request Jun 10, 2024
martinpitt added a commit to martinpitt/cockpit-machines that referenced this pull request Jun 10, 2024
martinpitt added a commit to martinpitt/cockpit-ostree that referenced this pull request Jun 10, 2024
martinpitt added a commit to cockpit-project/cockpit-ostree that referenced this pull request Jun 10, 2024
martinpitt added a commit to cockpit-project/cockpit-podman that referenced this pull request Jun 10, 2024
martinpitt added a commit to cockpit-project/cockpit-machines that referenced this pull request Jun 11, 2024
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.

Extend testlib with an easier keyboard API
2 participants