w3c / webdriver-bidi

Bidirectional WebDriver protocol for browser automation
https://w3c.github.io/webdriver-bidi/
378 stars 42 forks source link

input.Key{Down,Up}Action `value` is undefined #757

Closed martinpitt closed 3 months ago

martinpitt commented 4 months ago

input.performActions allows you to simulate key presses. E.g. typing an "a":

actions=[
        {"type": "key", "id": "key-0", "actions": [
        {"type": "keyDown", "value": "a"},
        {"type": "keyUp", "value": "a"}
]}])

The documentation currently just says value: text without any further explanation/definition.

With Chromium 126.0.6478.182 (as packaged in Fedora 40), supplying e.g. "hello" does not work:

bidi.WebdriverError: error: Invalid key value: hello

Now, that's fair -- I expected this to describe a single key, not series of keys. But curiously it does work with Firefox 128.0 (also as packaged in Fedora 40), and it succeeds typing "hello" into the web page.

My bigger concern is actually how to do non-ASCII keys. With CDP's Input.dispatchKeyEvent() you could press keys like ArrowLeft, Enter or Delete. But again with Chromium that just fails with

bidi.WebdriverError: error: Invalid key value: Enter

while with Firefox it types a literal "Enter" word.

So this is underspecified and inconsistent, and there doesn't seem to be a way how to input key names and/or modifiers like "Shift", "Control", and so on.

martinpitt commented 4 months ago

It doesn't belong into a bug report, but I have to let it out: I just love this spec: https://w3c.github.io/webdriver-bidi . Many thanks for this great work, and getting the browsers united behind it.

We are currently porting our tests from CDP to bidi, and it makes things so much more consistent and also easier. This is the only hiccup that I've found so far, and I suppose it's easy enough to work around by just synthesizing a web platform's KeyBoardEvent.

jgraham commented 4 months ago

WebDriver BiDi just depends on the WebDriver specification here, and providing multiple input characters is supposed to be an error, so that seems like a bug in Firefox.

To get non-printing characters PUA codepoints are used; see https://w3c.github.io/webdriver/#keyboard-actions

martinpitt commented 4 months ago

Thank you, that works. Could https://w3c.github.io/webdriver-bidi/#command-input-performActions link to https://w3c.github.io/webdriver/#keyboard-actions to make that more discoverable?

whimboo commented 4 months ago

@martinpitt would you mind filing a bug against Firefox? You can use this URL. Thanks.

Should we then close this issue?

Edit: Maybe we can close after adding a link which would indeed be helpful?

martinpitt commented 4 months ago

@whimboo Right, retitling accordingly. Indeed just adding that link to the classic spec would help a lot to understand the "value" field.

I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1910352 about that multi-character quirk.

jgraham commented 3 months ago

https://github.com/w3c/webdriver-bidi/pull/760