nightwatch.js无法在无头模式下运行chrome

如果没有打开可见的浏览器窗口,我无法运行它。 我用“无头的” 无头的 ”的论点来尝试

注意:我没有使用Selenium。

根据这个页面,从60版开始,MacOSX支持无头模式。我运行的是版本61

https://developers.google.com/web/updates/2017/04/headless-chrome

这是我的configuration:

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

你错过了–disable-gpu

正如您提供的url所提及的:

–disable-gpu \#暂时需要现在。

这意味着您现在需要使用无头模式,在将来的版本中可能不需要它。

如果你在Linux上,请尝试一下,这对我来说是完美的:

  "desiredCapabilities": { "browserName": "chrome", "javascriptEnabled": true, "acceptSslCerts": true, "chromeOptions": { "args": [ "headless", "disable-gpu" ], "binary": "/usr/bin/google-chrome" } } 

如果您在Mac上,请replace您的二进制文件path,例如/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

我之前遇到同样的问题,解决scheme是添加下面的参数,因为我不想要一个沙箱既不需要GPU。

“args”:[“headless”,“no-sandbox”,“disable-gpu”]

"chrome" : { "desiredCapabilities": { "javascriptEnabled": true, "acceptSslCerts": true, "browserName": "chrome", "chromeOptions" : { "args" : ["headless", "no-sandbox", "disable-gpu"] } } }