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

NightWatch Test failing in Selenium Grid : Timed out while waiting for element to be present for 10000 milliseconds. - expected "visible" but got: "not found" #2521

Closed rkhaneds closed 2 years ago

rkhaneds commented 3 years ago

Describe the bug

Timed out while waiting for element to be present for 10000 milliseconds. - expected "visible" but got: "not found"

Sample test

module.exports = { 'Search google': function (browser) { ​ browser .url('http://google.co.in/') .assert.titleContains('Google') .assert.visible('input[name="q"]') .sendKeys('input[name="q"]', 'nightwatch\n') .assert.containsText('.g .rc', 'Nightwatch.js') .end(); } }

Run with command npx nightwatch -e hostedGrid tests\search\google.js

Verbose output

D:\git\functional-tests\nightwatchjs-tests>npx nightwatch -e hostedGrid tests\search\google.js --verbose [Search\google] Test Suite

Configuration

module.exports = { src_folders: ["tests"], page_objects_path: ["page_objects"], globals_path: 'globals.js', ​ test_workers: { enabled: true, workers: 4 }, ​ test_settings: { default: { launch_url: 'http://google.com', webdriver: { start_process: true, port: 4444, server_path: require('chromedriver').path, }, desiredCapabilities: { browserName: 'chrome', chromeOptions: { args: [ "window-size=1280,800" ] } }, }, ​ hostedGrid: { launch_url: 'http://google.com', selenium: { start_process: false, port: 4444, host: "10.240.8.73", }, webdriver: { start_process: false, keep_alive: true, timeout_options: { timeout: 60000, retry_attempts: 3 } }, desiredCapabilities: { browserName: 'chrome', chromeOptions: { args: [ "start-maximized" ] }, } } } } Collapse

Executable Version
nightwatch --version ^1.4.3
npm --version 6.14.6
node --version V12.18.4
Browser driver Chrome 86.0.4
beatfactor commented 3 years ago

Try setting w3c: false.

rkhaneds commented 3 years ago

We tried with w3c: false in chrome options but still getting the same error. Please note we get error in Firefox as well.

Testing if element <input[name="q"]> is visible in 10000ms - expected "is visible" but got: "element could not be located"

rkhaneds commented 3 years ago

Issue happens in our hosted grid in open stack.

Test runs fine in locally created grid if started from nightwatch (i.e. selenium: { start_process: true, server_path: require('selenium-server').path,...}) (

rkhaneds commented 3 years ago

@beatfactor can we please get help on this, we got stuck and can't move forward. Please check and do the needful.

rkhaneds commented 3 years ago

@beatfactor any guidence for us will be really helpful.

rpala-commits commented 3 years ago

@beatfactor we are facing the same issue as well. We tried using w3c:fasle as per your recommendations for chromeoptions, firefoxoptions and safarioptions and still we are having issues with basic commands like

  1. waitForElementVisible
  2. waitForElementPresent
  3. setValues
  4. click

We did some further investigation to try and pinpoint where the problem resides and our findings are shown below. This consisted of executing a simple Nightwatch script against different versions of Selenium Servers/Selenium Grids. When trying different versions of Selenium Server we saw some improvement for some of the problems that are occurring. In some cases Nightwatch interacts with some browsers better than on other versions of Selenium Server but there doesn't appear to be a version of Selenium Server that will overcome enough of the compatibility issues

Please note: We have tested the sample example shown below on both Local selenium server and also on a docker container(Linux, chrome, firefox).

Nightwatch version: 1.5.1 Example: Sample test module.exports = { 'Search google': function (browser) { ​ browser .url('http://www.google.com') .waitForElementPresent('input[name="q"]') .waitForElementVisible('input[name="q"]') .sendKeys('input[name="q"]', 'nightwatch') .assert.containsText('.g .rc', 'Nightwatch.js') .end(); } }

Nightwatch.conf.js chrome: { desiredCapabilities: { browserName: "chrome", chromeOptions: { w3c: false } } }, firefox: { desiredCapabilities: { browserName: "firefox", platformName: "MAC", firefoxOptions: { w3c: false } } }

Outcome:

Nightwatch versionSelenium Server/Grid VersionWeb BrowserWeb Browser VersionNightwatchNotes
1.5.13.0.1Chrome87YESNo issues with the latest browser.
1.5.13.0.1Firefox83YESNo issues with the latest browser.
1.5.13.0.1Safari14.0.0YES 
1.5.13.0.1Safari14.0.1NOPost browser update, Safari 14.0.1 does not work with NightWatch 1.5.1
1.5.13.14.0Chrome87NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.14.0Firefox83NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.14.0Safari14.0.1NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.141.0Chrome87NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.141.0Firefox83NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.141.0Safari14.0.1NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.141.59 (latest stable release)Chrome87YESNo issues with the latest browser. May encounter issues when test with different versions of the same browsers
1.5.13.141.59 (latest stable release)Firefox83NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.13.141.59 (latest stable release)Safari14.0.1NOTest fails with a time out since its not able to do the basic check of element visible and even basic commands like input text and submit clicks fail with a timeout
1.5.14.0.0-alpha-7 (new alpha release)Chrome87NOFew commands work such as Input text and Clicking on Submit buttons, but command to check if element is visible(waitForElementVisible) & other Nightwatch native commands return 500 error.
1.5.14.0.0-alpha-7 (new alpha release)Firefox83NOFew commands work such as Input text and Clicking on Submit buttons, but command to check if element is visible(waitForElementVisible) & other Nightwatch native commands return 500 error.
1.5.14.0.0-alpha-7 (new alpha release)Safari14.0.1NOFew commands work such as Input text and Clicking on Submit buttons, but command to check if element is visible(waitForElementVisible) & other Nightwatch native commands return 500 error.

Any help/guidance would be greatly appreciated

leetmachine commented 3 years ago

running into a similar error on nightwatch 1.5.1 when running selenium grid 3 + chrome on fargate. Ours occurs broadly for things like .waitForElementPresent('body') or .waitForElementPresent('head'). I expect its a config issue between your browser setup and nightwatch capabilities config.

FWIW- I haven't gotten it to work but my research is as follows:

referenced issue: https://github.com/nightwatchjs/nightwatch/issues/2414

Others suggest to set chromeOptions w3c = false and args as follows:

//good explanation in readme: https://github.com/taktakpeops/selenium-grid-ecs-fargate

chromeOptions: {
          w3c: false,
          args: ['no-sandbox', 'disable-setuid-sandbox', 'headless', 'whitelist-ips', 'disable-dev-shm-usage']
        },

from: https://github.com/SeleniumHQ/selenium/issues/7476#issuecomment-519938952 In chromedriver 75+ you are expected to pass goog:chromeOptions as the key as chromeOptions itself is not w3c compliant. Instead if you w3c = false it is allowed chromeOptions.

Although, I attempted to pass both as received an error when passing goog:chromeOptions. It also does not appear like these settings were correctly applying to my session/ nightwatch correctly doing the config. I am still investigating but will post once I have solution.

EDITED: was able to get it working by adding this in nightwatch.conf.js:

['goog:chromeOptions']: {
          w3c: false,
          args: ['no-sandbox', 'disable-setuid-sandbox', 'headless', 'whitelist-ips', 'disable-dev-shm-usage']
        },
rpala-commits commented 3 years ago

Thanks for the follow up @leetmachine

I have some follow up questions:

  1. What selenium grid version are you using? Please note: we are able to run tests on chrome browser using seleniumgrid - 3.141.59, but the chrome tests fail on the latest seleniumgrid - 4.0.0-alpha-7
  2. Have you tried running your tests in firefox and safari browsers on Selenium grid? If so, can you share your results/any workarounds you may have considered?
mmkonrad commented 3 years ago

@leetmachine: Your are awesome!!!

@beatfactor: Since you are a maintainer....why must w3c be set to false? The official Nightwatch.js docs claims that it uses the W3C WebDriver API .... Does it have anything to do with the usage of custom commands? Any additional insights into the issue would help for the development of tests in the future.... We intend to use Nightwatch.js a lot and want to be as up to date and as compliant with modern standards as possible.

@rkhaneds Were you able to solve your issue with the solution introduced by @leetmachine ?

valemany commented 3 years ago

If you are using docker selenium grid you can try updating it to version 4, that solved the issue for me. Selenium grid 3 will be deprecated soon anyway. Note: If you use :latest docker will install version 3 still , you need to specify the version 4 for installation. Hope this is helpful to you too.

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.