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

Can't run NightwatchJS tests in headless mode #3024

Closed chan-chandra closed 2 years ago

chan-chandra commented 2 years ago

Test fail to run in headless mode when using NightwatchJS

steps

  1. Start with basic Demo code from https://nightwatchjs.org/
  2. Basic config file, Test file, package.json file is generated
  3. Chrome/ other browser runs properly
  4. But if changed to headless nightwatch.conf.js file, it shows error

Tried adding the following ways 1

 "args" : ["headless", "no-sandbox", "disable-gpu"],
          "binary": "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
 "args" : ["--headless"]

Example test

Demo.js

``` module.exports = { 'Demo test ecosia.org' : function(browser) { browser .url('https://www.ecosia.org/') .waitForElementVisible('body') .assert.titleContains('Ecosia') .assert.visible('input[type=search]') .setValue('input[type=search]', 'nightwatch') .assert.visible('button[type=submit]') .click('button[type=submit]') .assert.containsText('.mainline-results', 'Nightwatch.js') .end(); } }; ``` **Run with command** ```sh $ nightwatch test/demo.js ``` ### Verbose output

debug.log

``` FAILED: 1 assertions failed, 1 errors and 4 passed (10.322s) _________________________________________________ TEST FAILURE: 1 error during execution; 1 assertions failed, 4 passed (11.023s) ✖ Demo – Demo test ecosia.org (10.322s) Testing if element <.mainline-results> contains text 'Nightwatch.js' in 5000ms - expected "contains text 'Nightwatch.js'" but got: "element could not be located" (5487ms) at Object.Demo test ecosia.org (/Users/chanagonda/Documents/coe/qa-coe-experiments/nightwatchJS/tests/Demo.js:15:17) at processTicksAndRejections (internal/process/task_queues.js:95:5) NoSuchElementError: An error occurred while running .getText() command on <.mainline-results>: {"sessionId":"cde60139e1a3a480002b3dccedac52bf","status":0,"value":[]} at processTicksAndRejections (internal/process/task_queues.js:95:5) npm ERR! Test failed. See above for more details. ```

## Configuration
nightwatch.conf.json

```js module.exports = { "src_folders" : ["tests"], "webdriver" : { "start_process": true, "server_path": "node_modules/.bin/chromedriver", "port": 9515 }, "test_settings" : { "default" : { "desiredCapabilities": { "browserName": "chrome", "chromeOptions" : { "w3c": false, "args" : ["headless", "no-sandbox", "disable-gpu"], "binary": "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" }, acceptSslCerts: true } } }, } ```

## Your Environment | Executable | Version | | ---: | :--- | | `nightwatch --version` | 1.7.13 | | `npm --version` | 6.14.13 | | `node --version` | 14.17.2 | | OS | Version | | --- | --- | | macOS Monterey | 12.1 |
chan-chandra commented 2 years ago

@beatfactor @gravityvi @senocular could you please check on this issue, Thank you

gravityvi commented 2 years ago

@chan-chandra could you try this config instead:

 chrome: {
      desiredCapabilities: {
        browserName: 'chrome',
        'goog:chromeOptions': {
          // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
          //
          // w3c:false tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78)
          w3c: false,
          args: [
            //'--no-sandbox',
            //'--ignore-certificate-errors',
            //'--allow-insecure-localhost',
            '--headless'
          ]
        }
      },

      webdriver: {
        start_process: true,
        server_path: '',
        cli_args: [
          // --verbose
        ]
      }
    },
beatfactor commented 2 years ago

I suggest starting with the Quickstart Tutorial and if needed to run in headless, just pass the --headless argument (only works in Chrome, Edge, and Firefox).