nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.83k stars 1.32k forks source link

moveToElement does not work on Safari or Firefox #2469

Closed chris-jackson-actionqa closed 2 years ago

chris-jackson-actionqa commented 4 years ago

Describe the bug

Calling moveToElement() works on Chrome, but does not work with Firefox or Safari.

Sample test

sampleTest.js

```js // Please add the sample test here module.exports = { foo: function (browser) { browser.url("https://www.google.com"); const gSearch = "#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b"; browser.expect.element(gSearch).to.be.visible; browser.moveToElement(gSearch, 10, 10); browser.end(); }, }; ```

Run with command

$ nightwatch test/sampleTest.js -e firefox

$ nightwatch test/sampleTest.js -e safari

Verbose output

FIREFOX.debug.log

```txt -------------FIREFOX---------------------------------- [Check Commands] Test Suite =========================== ℹ Connected to localhost on port 4444 (2451ms). Using: firefox (79.0) on mac 18.5.0 platform. Running: foo ✔ Expected element <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b> to be visible (57ms) Error while running .moveTo() protocol action: An unknown error has occurred. FAILED: 1 errors and 1 passed (3.844s) _________________________________________________ TEST FAILURE: 1 error during execution; 0 assertions failed, 1 passed (6.503s) ✖ checkCommands – foo (3.844s) TimeoutError: An error occurred while running .moveToElement() command on <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b>: {"status":-1,"value":"HTTP method not allowed","errorStatus":-1,"error":"An unknown error has occurred.","httpStatusCode":405} at processTicksAndRejections (internal/process/task_queues.js:97:5) ```

SAFARI.debug.log

```txt [Check Commands] Test Suite =========================== ℹ Connected to localhost on port 4445 (20619ms). Using: Safari (12.1) on macOS platform. Running: foo Error while running .isElementDisplayed() protocol action: The command 'GET /session/5231F8CB-7429-43FD-AF4F-ECB106258372/element/node-D744DBF2-0D09-4AB9-BD96-57F89F7D5CE2/displayed' was not found. ✔ Expected element <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b> to be visible (26ms) Error while running .moveTo() protocol action: The command 'POST /session/5231F8CB-7429-43FD-AF4F-ECB106258372/moveto' was not found. FAILED: 1 errors and 1 passed (536ms) _________________________________________________ TEST FAILURE: 1 error during execution; 0 assertions failed, 1 passed (21.759s) ✖ checkCommands – foo (536ms) TimeoutError: An error occurred while running .moveToElement() command on <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b>: unknown command; The command 'POST /session/5231F8CB-7429-43FD-AF4F-ECB106258372/moveto' was not found. {"status":-1,"value":{"error":"unknown command","message":"The command 'POST /session/5231F8CB-7429-43FD-AF4F-ECB106258372/moveto' was not found.","stacktrace":""},"errorStatus":"","error":"The command 'POST /session/5231F8CB-7429-43FD-AF4F-ECB106258372/moveto' was not found.","httpStatusCode":404} at processTicksAndRejections (internal/process/task_queues.js:97:5) ```

Configuration

nightwatch.json

```js // Autogenerated by Nightwatch // Refer to the online docs for more details: https://nightwatchjs.org/gettingstarted/configuration/ const Services = {}; loadServices(); module.exports = { // An array of folders (excluding subfolders) where your tests are located; // if this is not specified, the test source must be passed as the second argument to the test runner. src_folders: ["./tests"], // See https://nightwatchjs.org/guide/working-with-page-objects/ page_objects_path: "", // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands custom_commands_path: "", // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-assertions custom_assertions_path: "", // See https://nightwatchjs.org/guide/#external-globals globals_path: "", webdriver: {}, test_settings: { default: { disable_error_log: false, launch_url: "https://nightwatchjs.org", screenshots: { enabled: false, path: "screens", on_failure: true, }, desiredCapabilities: { browserName: "firefox", }, webdriver: { start_process: true, server_path: Services.geckodriver ? Services.geckodriver.path : "", }, }, safari: { desiredCapabilities: { browserName: "safari", alwaysMatch: { acceptInsecureCerts: false, }, }, webdriver: { port: 4445, start_process: true, server_path: "/usr/bin/safaridriver", }, }, firefox: { desiredCapabilities: { browserName: "firefox", alwaysMatch: { // Enable this if you encounter unexpected SSL certificate errors in Firefox // acceptInsecureCerts: true, "moz:firefoxOptions": { args: [ // '-headless', // '-verbose' ], }, }, }, webdriver: { start_process: true, port: 4444, server_path: Services.geckodriver ? Services.geckodriver.path : "", cli_args: [ // very verbose geckodriver logs // '-vv' ], }, }, chrome: { desiredCapabilities: { browserName: "chrome", chromeOptions: { // This tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78) // w3c: false, // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/ args: [ //'--no-sandbox', //'--ignore-certificate-errors', //'--allow-insecure-localhost', //'--headless' ], }, }, webdriver: { start_process: true, port: 9515, server_path: Services.chromedriver ? Services.chromedriver.path : "", cli_args: [ // --verbose ], }, }, ////////////////////////////////////////////////////////////////////////////////// // Configuration for when using the browserstack.com cloud service | // | // Please set the username and access key by setting the environment variables: | // - BROWSERSTACK_USER | // - BROWSERSTACK_KEY | // .env files are supported | ////////////////////////////////////////////////////////////////////////////////// browserstack: { selenium: { host: "hub-cloud.browserstack.com", port: 443, }, // More info on configuring capabilities can be found on: // https://www.browserstack.com/automate/capabilities?tag=selenium-4 desiredCapabilities: { "bstack:options": { local: "false", userName: "${BROWSERSTACK_USER}", accessKey: "${BROWSERSTACK_KEY}", }, }, disable_error_log: true, webdriver: { keep_alive: true, start_process: false, }, }, "browserstack.chrome": { extends: "browserstack", desiredCapabilities: { browserName: "chrome", chromeOptions: { // This tells Chromedriver to run using the legacy JSONWire protocol // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/ w3c: false, }, }, }, "browserstack.firefox": { extends: "browserstack", desiredCapabilities: { browserName: "firefox", }, }, "browserstack.ie": { extends: "browserstack", desiredCapabilities: { browserName: "IE", browserVersion: "11.0", "bstack:options": { os: "Windows", osVersion: "10", local: "false", seleniumVersion: "3.5.2", resolution: "1366x768", }, }, }, ////////////////////////////////////////////////////////////////////////////////// // Configuration for when using the Selenium service, either locally or remote, | // like Selenium Grid | ////////////////////////////////////////////////////////////////////////////////// selenium: { // Selenium Server is running locally and is managed by Nightwatch selenium: { start_process: true, port: 4444, server_path: Services.seleniumServer ? Services.seleniumServer.path : "", cli_args: { "webdriver.gecko.driver": Services.geckodriver ? Services.geckodriver.path : "", "webdriver.chrome.driver": Services.chromedriver ? Services.chromedriver.path : "", }, }, }, "selenium.chrome": { extends: "selenium", desiredCapabilities: { browserName: "chrome", chromeOptions: { w3c: false, }, }, }, "selenium.firefox": { extends: "selenium", desiredCapabilities: { browserName: "firefox", "moz:firefoxOptions": { args: [ // '-headless', // '-verbose' ], }, }, }, }, }; function loadServices() { try { Services.seleniumServer = require("selenium-server"); } catch (err) {} try { Services.chromedriver = require("chromedriver"); } catch (err) {} try { Services.geckodriver = require("geckodriver"); } catch (err) {} } ```

Your Environment

Executable Version
nightwatch --version 1.3.7
npm --version 6.14.5
yarn --version na
node --version v14.3.0
Browser driver Version
NAME VERSION
chromedriver 84.0.4147.30
geckodriver 0.27.0
safaridriver Included with Safari 12.1 (14607.1.40.1.4)
OS Version
NAME VERSION
macOS Mojave 10.14.4
MuhammadTaha commented 4 years ago

I am running the code like

browser.moveToElement('.footer-container', 10, 10);

the error that I get is

 Error while running .moveTo() protocol action: An unknown error has occurred.

TimeoutError: An error occurred while running .moveToElement() command on <.footer-container>: undefined; undefined
   {"status":-1,"value":"HTTP method not allowed","errorStatus":-1,"error":"An unknown error has occurred.","httpStatusCode":405}
       at processTicksAndRejections (internal/process/task_queues.js:94:5)
chris-jackson-actionqa commented 4 years ago

Adding a comment to keep this issue alive. Our tests rely on this to verify hover state on elements.

jasontk19 commented 4 years ago

+1

I am seeing this as well but, only for some instances. It works in Firefox in some of our tests, fails in others. They all seem to work as expected in Chrome though.

ligarcia10 commented 4 years ago

+1 Same on Firefox: Error while running .moveTo() protocol action: mouseMoveTo

allanpfreitas commented 4 years ago

+1 for this one.

guergana commented 4 years ago

+1 Same here.

ituradastra commented 4 years ago

+1 for this one.

Pieras2 commented 4 years ago

This is firefox fault not nightwatch. Firefox doesnt want to do it.

pon., 9 lis 2020, 21:16 użytkownik s.i.p notifications@github.com napisał:

+1 for this one.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nightwatchjs/nightwatch/issues/2469#issuecomment-724253733, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMUVMH7R4K3O3PJPVJ66XRLSPBE23ANCNFSM4PX7WINQ .

Nuvelle commented 3 years ago

This is an issue for me too, without this our tests become overly complex or unuseable.

jcestibariz commented 3 years ago

I got the same error in Chrome with W3C mode enabled (chromeOptions: {w3c: true}):

 ✖ test
 – foo (616ms)

  TimeoutError: An error occurred while running .moveToElement() command on <#test>: unknown command; unknown command: Cannot call non W3C standard command while in W3C mode
   {"status":-1,"value":{"error":"unknown command","message":"unknown command: Cannot call non W3C standard command while in W3C mode","stacktrace":""},"code":"","errorStatus":"","error":"unknown command: Cannot call non W3C standard command while in W3C mode","httpStatusCode":404}                                                                                                                                                                                                                                                                  
       at processTicksAndRejections (internal/process/task_queues.js:93:5)

The problem is in https://github.com/nightwatchjs/nightwatch/blob/master/lib/transport/webdriver/actions.js, since there is no handler for moveTo it uses the default implementation which doesn't work in the W3C/WebDriver protocol.

tarheeldobe commented 3 years ago

I am also having a similar problem. I can retrieve element properties using .getLocation, but neither .click nor .moveToElement will scroll an element into the viewport. It is not working in Firefox (84.0.2), Chrome (88.0.4324.150). ChromeDriver (chromedriver-88.0.4324.96), Geckodriver (geckodriver-v0.29.0-win64). selenium-server-standalone-3.141.59. I have tried css selector and xpath selector. moveToElement error: move target out of bounds ... message":"(-8465, -648) is out of bounds of viewport width (1920) and height (966) ... org.openqa.selenium.interactions.MoveTargetOutOfBoundsException.

eleni-salamani commented 3 years ago

+1

cekeren commented 3 years ago

Having a similar issue with my setup. Running a basic test using Nightwatch+BrowserStack. The test works end to end every time on Chrome 89, but errors every time on Firefox 86. I clearly see loading fine when I check the page myself on Firefox whether locally or via BStack.

Side Note: I also get an error on maximizeWindow() on Firefox, but it works on Chrome.

Error: ✖ Timed out while waiting for element <body> to be present for 7000 milliseconds. - expected "visible" but got: "not found" (7636ms)

Code:


module.exports = {
  before: function (browser) {
    browser.globals.waitForConditionTimeout = 7000;
    browser
      .maximizeWindow()
      .url('$urlGoesHere')
      .waitForElementVisible('css selector', 'body')
      .percySnapshot('Login Page')
  }
kretschmannj commented 3 years ago

+1

lefablab commented 3 years ago

+1 for firefox

govind413 commented 3 years ago

+1 for Firefox

komal-thamke commented 3 years ago

Im having the same issue for firefox

luruena commented 3 years ago

+1 Firefox

jbobo commented 3 years ago

+1 Safari

gprovostqa commented 3 years ago

+1 for Firefox on nightwatch 1.7.8 with geckodriver 2.0.3

aakash3771 commented 3 years ago

+1 for Firefox on nightwatch 1.7.8 with geckodriver 2.0.2

gravityvi commented 3 years ago

This issue needs a change at the very core level( transport layer) in Nightwatch, unfortunately that can't be done in this major version. This has been resolved in Nightwatch v2 which is in alpha right now. Do check it out😄

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had any recent activity. If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.

kretschmannj commented 2 years ago

The moveToElement command is still failing even with Nightwatch v2 ...

Response 500 POST /wd/hub/session/f4976621-add3-4029-84a0-06c77facb8c3/actions (16ms) { value: { error: 'move target out of bounds', message: '(1174, 715) is out of bounds of viewport width (1366) and height (675)', stacktrace: '' } }

It seems that moveToElement is not scrolling the object into view. As a workaround, I had to manually scroll the window ...

browser.execute("scrollTo(0, 600)") // manually scroll the object into view

aakash3771 commented 2 years ago

I don't think this will be fixed as they are prioritising Actions

gravityvi commented 2 years ago

Hey @kretschmannj moveToElement command now takes offsets from the center of the webelement. The issue is not related to Nightwatch. As in the error response the offset provided is out of the bounds. Can you try using moveToElement(<element>,0 ,0)

IdeaHunter commented 2 years ago

@gravityvi Please reopen, facing the same problem in nightwatch 2.3.0, using 3 argument version with both zeros for x and y and still having error, my movement is in horizontal direction image

IdeaHunter commented 2 years ago

If my reflexes isnt lying to me its showing error when already moving in progress, once it even showed error multiple times during the move, using moveToElement with combination with xpath selectors

gravityvi commented 2 years ago

@IdeaHunter can you raise another issue looks like it's a different problem