WebDriverIO Selenium 将命令行参数从 config.js 文件传递​​到 Chrome

WebDriverIO Selenium pass command line arguments into Chrome from config.js file

我的 UI 测试需要 chrome 到 运行 禁用网络安全标志。如何使用 wdio.config 文件 (http://webdriver.io/) 注入任何命令。

  capabilities: [{
        browserName: 'chrome'
    }]

您可以使用 goog:chromeOptions

在所需功能范围内设置任何 chrome 标志
capabilities: [{
    browserName: 'chrome',
    'goog:chromeOptions': {
        args: ['disable-web-security']
    }
}]

查看 the chromedriver docs 了解有关 chrome 选项对象的更多信息。

这是正确的语法,谢谢 Christian!

  capabilities: [{
        browserName: 'chrome',
         'goog:chromeOptions': {
            args: ['--disable-web-security']
        }
    }]

如果您想在使用 webdriverio 的浏览器中禁用 javascript,在您的 wdio.config 中您需要

capabilities: [{
    browserName: 'chrome',
     'goog:chromeOptions': {
            "args" : ["start-fullscreen"],
            "prefs" : {
                    'profile.managed_default_content_settings.javascript': 2
            }
    }
}]

某些内容已更改,因为在 @wdio/cli 版本 5.11.13chromedriver 版本 76.0.0 中我无法传递参数 chromeOptions - 结果:invalid argument: unrecognized capability: chromeOptions.

我做了一些研究并通过了 goog:chromeOptions 作品:

  capabilities: [{
    browserName: 'chrome',
    'goog:chromeOptions': {
      args: ['--disable-web-security'],
    },
  }]