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

Chrome headless for nightwatch #1390

Closed smartbub17 closed 7 years ago

smartbub17 commented 7 years ago

Is it possible to use chrome headless in nightwatch? I've tried adding "--headless" but no luck.

"desiredCapabilities": {
    "browserName": "chrome",
    "javascriptEnabled": true,
    "chromeOptions" : {
       "args" : ["--headless"]
    }
}
mattpardee commented 7 years ago

I'm not aware of a way but could you achieve the same goal by using PhantomJS? https://github.com/nightwatchjs/nightwatch/wiki/Running-tests-in-PhantomJS

marlun commented 7 years ago

According to https://twitter.com/addyosmani/status/825418982588968960 it's on its way for mac but available for linux.

utajum commented 7 years ago

It works

"chromeOptions" : {
       "args" : ["headless"]
    }
mitul45 commented 7 years ago

It works now. According to: https://github.com/nightwatchjs/nightwatch/issues/1439#issuecomment-296199244.

"desiredCapabilities": {
   "browserName": "chrome",
   "chromeOptions": {
       "args": [
           ""--headless"
        ],
        "binary": "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary"
     }
}
ozymandias547 commented 7 years ago

Glad this works out of the box. thanks everyone!

jay-jlm commented 7 years ago

Cannot get it run without opening a visible web browser on MacOSX, even thou this page says it should be already available: https://developers.google.com/web/updates/2017/04/headless-chrome

(Page says it requires v60 and I am using v61)

straris commented 6 years ago

Running headless chrome 61 with selenium 3.6.0 will result in an empty page in localhost:9222 with data., in the url.

I am using the following chrome configuration:

chromeOptions: {
    args: ['--headless', '--remote-debugging-port=9222', '--disable-gpu=true']
  }

The only logging in chrome driver: Starting ChromeDriver 2.33.506106 (8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2) on port 32627 Only local connections are allowed.

Same setup works fine with normal gui Chrome. Any hints? :(

imthefrizzlefry commented 6 years ago

I have been able to run Chrome 61.0.3163.100 (official) with Selenium 2.53.0. Our config file looks like this:

"chrome-headless": {
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "chromeOptions": {
          "args": [
            "headless",
            "disable-web-security",
            "ignore-certificate-errors"
          ]
        }
      }
    }

Could it be a Selenium 3.6.0 issue?

straris commented 6 years ago

@imthefrizzlefry after trying out your config looks like it works indeed. The culprit was '--remote-debugging-port=9222', can't say if it's selenium or nightwatch issue though..

malquda1 commented 6 years ago

It works for me on Linux only, did any one had some luck with Windows?

This is my config.json for Nightwatch (Windows), I am using the same for Linux but i am switching chrome driver, chrome binary.

{
  "src_folders": [
    "tests"
  ],
  "output_folder": "test-reports-system",
  "selenium": {
    "start_process": true,
    "server_path": "./bin/selenium-server-standalone-3.5.0.jar",
    "log_path": "./logs",
    "port": 4444,
    "cli_args": {
      "webdriver.chrome.driver": "./bin/win32/chromedriver_2.33_win32.exe"
    }
  },
  "test_settings": {
    "default": {
      "launch_url": "http://localhost",
      "selenium_port": 4444,
      "selenium_host": "localhost",
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "chromeOptions" : {
          "args" : ["disable-web-security", "ignore-certificate-errors", "headless"],
          "binary": "./bin/win32/chromium-win32/chrome.exe"
        }
      }
    }
  },
  "custom_commands_path" : "./node_modules/nightwatch-custom-commands-assertions/js/commands",
  "custom_assertions_path" : "./node_modules/nightwatch-custom-commands-assertions/js/assertions"
}
acol4k commented 6 years ago

Wonder if that is a good UI testing then... since we do not open browser at all... I have Jenkins running all my tests in headless mode.. Hm, do not have much experience so I wonder if it's reliable as when we run tests with Browser opening? If anyone has experience I would love to hear, it would be of a great help to decide witch road to go... :) Thanks!

jay-jlm commented 6 years ago

Hey @acol4k , don't forget that github issues is not proper place to ask general questions or ask for advice. There are proper channels to do that.

acol4k commented 6 years ago

Ha ha :) Actually I did not know that either.. sorry man :) And you were of great help! Thanks

kathydingcn commented 6 years ago

I got the similar issue recently. All the elements can not be found under headless mode. I did more debug and found that is because the lanuch URL need SSL certification. I added one option acceptInsecureCerts. It works now. Hopefully this is helpful. "desiredCapabilities": { "browserName": "chrome", "acceptSslCerts": true, "acceptInsecureCerts": true, "chromeOptions" : { "args": [ "headless", "no-sandbox", "disable-gpu", "ignore-certificate-errors" ], "binary" : "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" } },

linxianying commented 6 years ago

Hello, is there anyone knows if headless works for Windows now?

soletan commented 5 years ago

Using chromedriver installed via npm it works for me under Windows (in a current VueJS project) using this nightwatch.config.js:

module.exports = {
    globals_path: "./tests/e2e/globals.js",
    selenium: {
        start_process: false
    },
    test_settings: {
        default: {
            selenium_port: 9515,
            selenium_host: "localhost",
            default_path_prefix: "",

            desiredCapabilities: {
                browserName: "chrome",
                chromeOptions: {
                    args: [
                        "--headless",
                    ]
                },
                acceptSslCerts: true
            }
        }
    }
};

Removing --headless from args array causes the browser to pop up again.

GelbardSteve commented 4 years ago
        "chromeOptions": {
          "w3c": false,
          "args" : ["headless"]
        }