You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In files we recently had to support testing ArrowDown and ArrowUp keys, I noticed that puppeteer/playwright have a nice API for this which is something like:
This makes tests easier readable, as we usually do:
b.key_press(chr(27)) # escape
Our key_press function can also write text:
b.key_press("logs")
Which in pupeteer/playwright is:
keyboard.type("logs")
Furthermore key_press is split into a Firefox and Chrome specific function which in essence does:
For chromium:
Set windowsVirtualKeyCode for when use_ord is set or modifiers is set or key is not alphanum or ord(key) < 32 (special keys).
For Firefox:
*we have a small dict with key maps for Backspace/enter if use_ord is set or order(key) < 32 we convert the key into Escape.
In files we recently had to support testing
ArrowDown
andArrowUp
keys, I noticed that puppeteer/playwright have a nice API for this which is something like:This makes tests easier readable, as we usually do:
Our
key_press
function can also write text:Which in pupeteer/playwright is:
Furthermore
key_press
is split into a Firefox and Chrome specific function which in essence does:For chromium:
windowsVirtualKeyCode
for whenuse_ord
is set or modifiers is set or key is not alphanum or ord(key) < 32 (special keys).For Firefox:
*we have a small dict with key maps for Backspace/enter if
use_ord
is set ororder(key) < 32
we convert the key into Escape.So for example escape becomes this for Chromium:
What playwright does, is keep a map with keycodes for all special keys https://github.com/microsoft/playwright/blob/dd1a9f5e9637c37b25ca05e83c860b32abb7930d/packages/playwright-core/src/server/usKeyboardLayout.ts#L28
And then send this over to CDP. Another notable difference is that they send
rawKeydown
for non-text, I am assume that would for example beEnter
.https://github.com/microsoft/playwright/blob/dd1a9f5e9637c37b25ca05e83c860b32abb7930d/packages/playwright-core/src/server/chromium/crInput.ts#L58
From my testing I have found out sending special keys do work as Firefox in Chromium for Delete/Arrow keys in files with:
However in Cockpit this does not work for
TestPages.testMenuSearch
and I need to sendwindowsVirtualKey
.Proposal
Split off our API, add:
b.keyboard.press
b.keyboard.down
b.keyboard.up
andb.keyboard.type
and deprecateb.key_press
Alternative:
Keep
key_press
and addtype_text
.Some interesting usage:
\b
==Backspace
so writingpress_key(
Backspace`) is way easier to read but not as usable (it would need a loop).The text was updated successfully, but these errors were encountered: