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.78k stars 1.31k forks source link

getLocationInView() does not work on Firefox or Safari #2470

Closed chris-jackson-actionqa closed 3 years ago

chris-jackson-actionqa commented 4 years ago

Describe the bug

getLocationInView() does not work in Firefox or Safari. Works fine on Chrome.

Sample test

sampleTest.js

```js 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.getLocationInView(gSearch, (result) => { console.log(result.value); }); browser.end(); }, }; ```

Run with command

$ nightwatch test/sampleTest.js -e firefox

$ nightwatch test/sampleTest.js -e safari

Verbose output

FIREFOX.debug.log

```txt [Check Commands] Test Suite =========================== ℹ Connected to localhost on port 4444 (2437ms). 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 (54ms) Error while running .isElementLocationInView() protocol action: An unknown error has occurred. { error: 'An error occurred while running .getLocationInView() command on <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b>: ', message: 'An error occurred while running .getLocationInView() command on <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b>: ', stack: 'TimeoutError: An error occurred while running .getLocationInView() command on <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b>: \n' + ' at PeriodicPromise.getError (/Users/cjackson/Documents/nwCheckCrap/node_modules/nightwatch/lib/utils/periodic-promise.js:161:12)\n' + ' at PeriodicPromise.perform (/Users/cjackson/Documents/nwCheckCrap/node_modules/nightwatch/lib/utils/periodic-promise.js:111:16)\n' + ' at processTicksAndRejections (internal/process/task_queues.js:97:5)\n' + ' at async PeriodicPromise.runAction (/Users/cjackson/Documents/nwCheckCrap/node_modules/nightwatch/lib/utils/periodic-promise.js:48:22)\n' + ' at async PeriodicPromise.runAction (/Users/cjackson/Documents/nwCheckCrap/node_modules/nightwatch/lib/utils/periodic-promise.js:51:16)' } FAILED: 1 errors and 1 passed (2.522s) _________________________________________________ TEST FAILURE: 1 error during execution; 0 assertions failed, 1 passed (5.175s) ✖ checkCommands – foo (2.522s) TimeoutError: An error occurred while running .getLocationInView() 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 (10624ms). Using: Safari (12.1) on macOS platform. Running: foo Error while running .isElementDisplayed() protocol action: The command 'GET /session/38A3C311-C0D9-462E-A1C9-0C8AE9CC1F04/element/node-C5FB4E05-6CEC-41FB-BC1F-1308421703AC/displayed' was not found. ✔ Expected element <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b> to be visible (24ms) Error while running .isElementLocationInView() protocol action: The command 'GET /session/38A3C311-C0D9-462E-A1C9-0C8AE9CC1F04/element/node-C5FB4E05-6CEC-41FB-BC1F-1308421703AC/location_in_view' was not found. { error: "An error occurred while running .getLocationInView() command on <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b>: unknown command; The command 'GET /session/38A3C311-C0D9-462E-A1C9-0C8AE9CC1F04/element/node-C5FB4E05-6CEC-41FB-BC1F-1308421703AC/location_in_view' was not found.", message: "An error occurred while running .getLocationInView() command on <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b>: unknown command; The command 'GET /session/38A3C311-C0D9-462E-A1C9-0C8AE9CC1F04/element/node-C5FB4E05-6CEC-41FB-BC1F-1308421703AC/location_in_view' was not found.", stack: "TimeoutError: An error occurred while running .getLocationInView() command on <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b>: unknown command; The command 'GET /session/38A3C311-C0D9-462E-A1C9-0C8AE9CC1F04/element/node-C5FB4E05-6CEC-41FB-BC1F-1308421703AC/location_in_view' was not found.\n" + ' at PeriodicPromise.getError (/Users/cjackson/Documents/nwCheckCrap/node_modules/nightwatch/lib/utils/periodic-promise.js:161:12)\n' + ' at PeriodicPromise.perform (/Users/cjackson/Documents/nwCheckCrap/node_modules/nightwatch/lib/utils/periodic-promise.js:111:16)\n' + ' at processTicksAndRejections (internal/process/task_queues.js:97:5)\n' + ' at async PeriodicPromise.runAction (/Users/cjackson/Documents/nwCheckCrap/node_modules/nightwatch/lib/utils/periodic-promise.js:48:22)\n' + ' at async PeriodicPromise.runAction (/Users/cjackson/Documents/nwCheckCrap/node_modules/nightwatch/lib/utils/periodic-promise.js:51:16)' } FAILED: 1 errors and 1 passed (505ms) _________________________________________________ TEST FAILURE: 1 error during execution; 0 assertions failed, 1 passed (11.755s) ✖ checkCommands – foo (505ms) TimeoutError: An error occurred while running .getLocationInView() command on <#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.gNO89b>: unknown command; The command 'GET /session/38A3C311-C0D9-462E-A1C9-0C8AE9CC1F04/element/node-C5FB4E05-6CEC-41FB-BC1F-1308421703AC/location_in_view' was not found. {"status":-1,"value":{"error":"unknown command","message":"The command 'GET /session/38A3C311-C0D9-462E-A1C9-0C8AE9CC1F04/element/node-C5FB4E05-6CEC-41FB-BC1F-1308421703AC/location_in_view' was not found.","stacktrace":""},"errorStatus":"","error":"The command 'GET /session/38A3C311-C0D9-462E-A1C9-0C8AE9CC1F04/element/node-C5FB4E05-6CEC-41FB-BC1F-1308421703AC/location_in_view' 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
chris-jackson-actionqa commented 4 years ago

Adding a comment to keep this issue alive.

I discovered this using the nightwatch-vrt plugin. Fixing this issue would allow our team to do some visual regression testing with this plugin.

Sorry, I tried stepping in and debugging myself, but I haven't had success, yet.

beatfactor commented 4 years ago

This seems to be a deprecated command which was removed from W3C Webdriver, but the same result can easily be achived with: moveToElement() and getLocation(). The only difference between getLocation() and getLocationInView() is that the latter scrolls the element in view.

Edit: Never mind, I see (in #2469) that moveToElement doesn't work either. I'll look into it.

chris-jackson-actionqa commented 4 years ago

Thank you for investigating. I can file an issue with the nightwatch-vrt plugin to stop using getLocationInView.

stale[bot] commented 3 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.

gprovostqa commented 3 years ago

+1 for Firefox on nightwatch 1.7.8 with geckodriver 2.0.3

tomillie commented 2 years ago

+1, nightwatch 2.1.8 and geckodriver 3.0.1

shankar0001 commented 2 years ago

I am running the Night-watch VRT tests on firefox browser but the image was not captured correctly inside baseline folder.

Can anyone help me on this issue.

firefox (103.0.2) and running firefox on Safari browser.

visual_regression_settings: { latest_screenshots_path: 'vrt/latest', latest_suffix: '_ls', baseline_screenshots_path: 'vrt/baseline', baseline_suffix: '_bs', diff_screenshots_path: 'vrt/diff', diff_suffix: '_ds',

Screenshot 2022-08-22 at 1 01 08 PM

threshold: 0.05, prompt: false, always_save_diff_screenshot: false, }, CAPTURED image by VRt Attached