wdio chrome headless并不是无头运行



无头铬对我来说似乎不是无头的。我使用wdio,并将其作为我的配置:

capabilities: [
{
// maxInstances can get overwritten per capability. So if you have an in-house Selenium
// grid with only 5 firefox instances available you can make sure that not more than
// 5 instances get started at a time.
maxInstances: 5,
//
browserName: 'chrome',
args: ['--headless', '--disable-gpu', '--window-size=1280,800'],
binary: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
}
]

我还在浏览器启动前输出功能:

{
"maxInstances": 5,
"browserName": "chrome",
"args": [
"--headless",
"--disable-gpu",
"--window-size=1280,800"
],
"binary": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
}

我的chrome浏览器正在启动,我可以看到网络驱动程序正在进行测试。我有很多帖子都是用这种方式做的,它应该只是起作用。我错过了什么?


更新

我已经修改了从环境变量中读取的功能。如果我使用BROWSER=chrome,我会看到正确的功能通过,浏览器会在chrome中启动。如果我使用BROWSER=firefox,firefox就会打开,我看到了适当的功能。如果我不使用任何我认为合适的功能,chrome会打开,但它不是无头的。

const CHROME = {
browserName: 'chrome',
};
const FIREFOX = {
browserName: 'firefox',
};
const CHROME_HEADLESS = {
browserName: 'chrome',
args: ['headless', 'disable-gpu']
};
function getCapabilities() {
let browser;
switch(process.env.BROWSER && process.env.BROWSER.toLowerCase()) {
case 'chrome':
browser = CHROME;
break;
case 'firefox':
browser = FIREFOX;
break;
default:
browser = CHROME_HEADLESS;
break;
}
return [Object.assign({maxInstances: 5}, browser)];
}

要接受已接受的答案,在Selenium(3.8及更高版本(的较新版本中,您可能必须将chromeOptions指定为"goog:chromeOptions"

https://gist.github.com/disintegrator/ff6e9341860e9b121099c71bc9381bd6

拥有铬选项中的功能

它对我来说很好。

capabilities: [
{
      browserName: 'chrome',
      chromeOptions: {
        args: ['headless', 'disable-gpu'],
      },
    },
  ],

相关内容

最新更新