【问题标题】:wdio chrome headless is not running headlesslywdio chrome headless 没有无头运行
【发布时间】: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


    【解决方案1】:

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

    在您的 chrome 选项中包含这些功能。

    对我来说很好用。

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

    【讨论】:

    • 我在 onPrepare、beforeSession 和 before 上 console.log(JSON.stringify(capabilities,false,2)),功能正是我所期望的,包括 args。
    • 你使用 selenium 服务器对吗?你为什么提到二进制文件?
    • 我正在使用 selenium 服务器。我把它拿出来,结果是一样的。我保留它是因为我看到的例子中有它。
    • 您是否在功能数组中提供了参数?
    • 在应该可以工作的 chrome 选项中包含 args。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-18
      • 2019-05-08
      • 1970-01-01
      • 2018-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多