【发布时间】:2018-11-06 04:10:49
【问题描述】:
Headless chrome 对我来说似乎不是无头的。我正在使用 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 浏览器正在启动,我可以看到 webdriver 正在驱动测试。我有很多帖子都以这种方式进行操作,并且应该可以正常工作。我错过了什么?
更新
我已经修改了从环境变量中读取的功能。如果我使用 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)];
}
【问题讨论】:
标签: webdriver-io google-chrome-headless