Skip to content

Add support for W3C actions to node client #4564

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

Closed
noyainrain opened this issue Aug 24, 2017 · 19 comments
Closed

Add support for W3C actions to node client #4564

noyainrain opened this issue Aug 24, 2017 · 19 comments
Assignees
Labels
C-nodejs JavaScript Bindings

Comments

@noyainrain
Copy link

noyainrain commented Aug 24, 2017

tl;dr Please implement the W3C actions API for the node client.

Using the latest selenium-webdriver node client (3.5) to drive a local instance of the latest Firefox (55) on Linux, calling the user interactions API results in the infamous UnknownCommandError: POST /session/[...]/moveto did not match a known command error.

To my understanding, Firefox / geckodriver has implemented the W3C actions API, while the node client at the moment only supports an older version of the API (having a quick look at http.js, the /actions endpoint is missing).

It seems this has already been implemented in other language bindings, for example the Java client. It would be awesome if we could get W3C action support for the node bindings to :) .

PS: Thanks for your great work on Selenium!

@kaiyoma
Copy link

kaiyoma commented Sep 18, 2017

I just ran into this as well. I'm running tests on Windows with Firefox 55 and a recent version of the gecko driver and I'm getting this error:

UnknownCommandError: POST /session/ff91f250-8eb1-44ba-94ae-1c55b5a96629/moveto did not match a known command

(Full bug report: mozilla/geckodriver#958)

My tests work perfectly in Chrome and Chrome Headless, but not Firefox.

@dlgoodchild
Copy link

Just hit this too running selenium standalone firefox docker container.

image: "selenium/standalone-firefox-debug:3.6.0-bromine"

@jleyba jleyba self-assigned this Oct 8, 2017
jleyba added a commit that referenced this issue Oct 9, 2017
…for legacy

actions.

This is going to hurt users one way or the other: chrome currently only supports
legacy actions and firefox only supports W3C. Since all JS changes are now
targeting 4.0 (a major version bump), we're dropping support for legacy and
moving forward with W3C only.

For #4564, #4662
@jleyba
Copy link
Contributor

jleyba commented Oct 9, 2017

I completely overhauled the actions API to support W3C. I'm not entirely sure how I feel about the API (or the API for any of the language bindings for that matter). It's kind of difficult to setup given how you can define parallel sequences across multiple devices.

Please take a look and let me know what you think -- note I'm not planning on publishing another npm release until 4.0, so you'll have to grab this from head.

I'm hoping for feedback on documentation [1] and overall usage [2].

[1] https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/lib/webdriver.js#L2522
[2] https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/test/actions_test.js

@noyainrain
Copy link
Author

Hey @jleyba, sorry for the late reply, had some busy days.

First, thank you for implementing the new API, that's awesome! 👍

After having a look at the W3C spec, I think the proposed API captures it pretty well. Some thoughts:

  • input.Sequence might benefit from a perform() method (just a wrapper around ActionSequence.perform()), so we could still write one-liners for simple use cases, e.g. driver.actions().mouse().click(elem1).click(elem2).perform();.
  • How would we make use of multiple pointers / fingers? Something like actions().touch(0).move(...) and actions().touch(1).move(...)?
  • The idea of synchronize() is neat. The documentation for ActionSequence may be a bit clearer if it showed an example of pause() and then went on with something like "... This can get cumbersome. Rather than keeping track of the number of steps for the keyboard to pause..."

I see you removed support for the legacy version of ActionSequence. For our project, at the moment we only support testing on Chrome but not Firefox and this would just swap the problem. Would you consider keeping the legacy version around until the next major release (5), for example with an extra argument like actions(legacy=true)?

It would be even better for backward compatibility if the old ActionSequence interface could internally use the new W3C actions protocol if available and fall back otherwise. I know that this may involve extra effort better spent elsewhere, just saying it for completeness sake :) .

@noyainrain
Copy link
Author

Just a short addition to the previous feedback:

I've refactored one of our UI tests to use the new API, ran it with a current local Firefox and everything works as expected :) .

Without the legacy version available, it does not work with any other common browser, as none has implemented the new spec yet:

@jleyba
Copy link
Contributor

jleyba commented Dec 18, 2017

Thanks for the feedback. I think I'm going to try to transparently support the legacy protocol (if W3C actions fail, it will translate to legacy and try again). I just started looking at it, but I'm hoping to have something to push within a few days.

jleyba added a commit that referenced this issue Dec 21, 2017
…API,

translate actions to a command sequence against the legacy API and try again.

This change only supports translating mouse and keyboard actions. A subsequent
change will add support for translating touch pointers.

(For #4564)
jleyba added a commit that referenced this issue Dec 21, 2017
jleyba added a commit that referenced this issue Dec 27, 2017
-  Update documentation
-  Resurrect the legacy API (too difficult to accurately translate touch actions
   in the new API to legacy commands). The legacy API will be removed once
   Chrome and Edge support the new API.

For #4564
jleyba added a commit that referenced this issue Jan 8, 2018
The previous iteration heavily favored sequences where multiple devices acted
in each tick. This also made it too difficult for "simple" sequences like
"press SHIFT, move the mouse (0, 30), press LEFT, release LEFT, etc." This new
version goes back to favoring simple, synchronous sequences, but still allows
configuring async sequences.

The new input.Actions class API is largely compatible with
actions.LegacyActionSequence, however, the mouse methods have been renamed to
force a breakage since there is a change in parameters.

The new API still supports translating mouse+keyboard sequences to the legacy
protocol, but users have to explicitly request this when the sequence is first
created (translation is opt-in because it's not 100%; known issues are all
covered in the input.Actions class doc)
@jleyba
Copy link
Contributor

jleyba commented Jan 8, 2018

OK, I'm happier with this latest version. It's pretty similar to the legacy API, but still makes it possible to define parallel actions for the browsers that support it (right now just Firefox). The new API does support translating to mouse+keyboard actions to the legacy API, but it's not 100%, so you have to explicitly enable this behavior (see the new docs for details)

No browsers currently support touch/pen actions with W3C actions, so those aren't surfaced through the API yet.

@jleyba
Copy link
Contributor

jleyba commented Jan 13, 2018

The new API is included in 4.0.0-alpha.1, which has been published to npm

@jleyba jleyba closed this as completed Jan 13, 2018
@sahil1610
Copy link

@jleyba I am still facing the same issue with 4.0.0-alpha.1.

POST /session/{sessionId}/moveto did not match a known command

@biot023
Copy link

biot023 commented Feb 18, 2018

I'm seeing this with 4.0.0-alpha.1, too.
The error I'm getting is this:

node:13870) UnhandledPromiseRejectionWarning: UnsupportedOperationError:

<title>Error</title>
Cannot POST /session
at parseHttpResponse (/home/mycomputer/work/home/dp/0_dev/node_modules/selenium-webdriver/lib/http.js:557:11)
at Executor.execute (/home/mycomputer/work/home/dp/0_dev/node_modules/selenium-webdriver/lib/http.js:468:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:160:7)

(node:13870) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13870) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Ah, markdown is stripping some data out. Basically I'm getting an HTML file output that complains in a PRE tag that it "Cannot POST /session".
I'm not asking it to post to a /session url anywhere in my code.

@alexandergallen
Copy link

@jleyba does this also have an affect when using directConnect in protractor? or does it then skip all selenium related issues?

@jleyba
Copy link
Contributor

jleyba commented Mar 21, 2018

@sahil1610 & @biot023 you have to use driver.actions({bridge:true}) to enable the fallback behavior. In hindsight, I should have made strict-W3C compliance opt-in. I'll fix that for the next release.

@alexandergallen Sorry, I have no idea what "directConnect in protractor" is.

@jleyba jleyba reopened this Mar 21, 2018
@MagicPoulp
Copy link

MagicPoulp commented Jun 4, 2018

jleyba,
With try/catch you could detect this error and write in the error message to suggest people to use {bridge: true} to fallback to the legacy API

W3C actions were 3 months ago only supported in firefox. Since actions are broken on HEAD for chrome (were 3 months ago), we need clearer error messages, or doc about the legacy fallback that is very nice.

@jleyba
Copy link
Contributor

jleyba commented Jun 5, 2018

@MagicPoulp pull requests are always welcome

@fcheslack
Copy link

On 4.0.0a1
When using the
driver.actions({bridge:true})
most driver functions I am using now work as expected, however attempting to access browser logs
via driver.manage().logs().getAvailableLogTypes() or driver.manage().logs().get('browser')
I still get a
UnknownCommandError: GET /session/75b679f8-3544-46d2-94ec-16e442857fbb/log/types did not match a known command
or
UnknownCommandError: POST /session/655265ba-2324-4f3c-86bc-8894564098a0/log did not match a known command

@MagicPoulp
Copy link

"@MagicPoulp pull requests are always welcome"

My suggestion was to do mainly documentation. Something as fundamental as using actions was broken on HEAD.

WHen something does not work, it is common for people to have a look at the CHANGES. This is where I learnt about the W3C thing.

The fallback mechanism you provided is not 100% "plug-and-play". People still get errors when they don't know about it, you should document.

I had other issues with actions with actions involving SVG DOM objects not behaving the same across browsers.

--> suggestion to improve the quality of this repo (it is already of quality the Javascripy selenium is much cooler than in other frameworks 100%):
documentation, keeping backward compatibility (actions were broken on HEAD whilst they worked before), good commits names, commit time in chronological order (they are not in chronological order so I had difficulty to find the first commit where the error happened, and the nI could report you that it was broken on HEAD and then you made teh fallback mechanism)

@diemol
Copy link
Member

diemol commented Sep 11, 2020

This has been open for a while but I believe W3C actions should be already implemented in the JS bindings, do you know if this is true @harsha509?

@harsha509
Copy link
Member

Hi @diemol ,

Yes, W3C actions are implemented in the JavaScript bindings (Checked in alpha 4 versions, also we have good code samples tested in here https://www.selenium.dev/documentation/en/support_packages/mouse_and_keyboard_actions_in_detail/).

But, Am not sure if this thread contains discussion about any other issue (as i see lot of tagged links of issues from protractor).

This issue is also referenced in selenium-ide too in here SeleniumHQ/selenium-ide#329, So @corevo comments also will be helpful in conforming this.

Thanks,
Harsha

@diemol
Copy link
Member

diemol commented Sep 12, 2020

Thanks, @harsha509!
The issue is only about W3C actions for JS in this repo.
I'll close it then.

@diemol diemol closed this as completed Sep 12, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Sep 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-nodejs JavaScript Bindings
Projects
None yet
Development

No branches or pull requests