【问题标题】:Toggling multiCapabilites config based on cucumber tag基于黄瓜标签切换 multiCapabilites 配置
【发布时间】:2017-07-26 14:51:44
【问题描述】:

我想知道是否有人找到了一种在来自 cucumber.conf.js 文件的不同 multiCapabilities 配置之间切换的方法。目前我有一个配置,它将运行并行 chrome 驱动程序来运行测试。

multiCapabilities: [{
    'browserName': 'chrome',
    'platform': 'ANY',
    shardTestFiles: true,
    maxInstances: 2
}],

但是,如果我还想为多浏览器测试添加一个 multiCapabilities 选项怎么办

multiCapabilities: [{
    'browserName': 'chrome'
},{
    'browserName': 'firefox'
}]

我宁愿不想注释掉或更改代码,而是存储一些我可以使用诸如标志、标签或 grunt 选项之类的东西来切换的 multiCapabilities 配置。有没有人有这样的运气?谢谢!

【问题讨论】:

  • 如果您使用 gulp,那么以编程方式执行此操作将是微不足道的。也许不是你想听到的,但这就是我所听到的。
  • 不,不使用 gulp - 希望在任务运行器之外寻找解决方案。但是谢谢你:)

标签: javascript selenium protractor cucumberjs


【解决方案1】:

最好的办法是使用量角器的内置命令行选项来传递浏览器或在任何此类功能之间切换。

Usage: protractor [configFile] [options]
configFile defaults to protractor.conf.js
The [options] object will override values from the config file.
See the reference config for a full list of options.

Options:
--help                                 Print Protractor help menu
--version                              Print Protractor version
--browser, --capabilities.browserName  Browsername, e.g. chrome or firefox

如果您查看量角器的 cli 选项,并且如果您在 multicapabilties 选项中设置了多个浏览器,则可以像这样传递浏览器名称 -

protractor config.js --capabilities.browserName='chrome'
protractor config.js --capabilities.browserName='firefox'

您可以在 package.json 中将其设置为单独的脚本,以在各种浏览器中运行测试 -

"scripts": {
"tsc": "tsc",
"test": "protractor ./config.js",
"chrome-tests": "protractor ./config.js --capabilities.browserName='chrome'",
"firefox-tests": "protractor ./config.js --capabilities.browserName='firefox'"
}

现在您可以使用 npm 调用它 -

npm run chrome-tests // it would run your tests in chrome browser
npm run firefox-tests // it would run your tests in firefox browser

您还可以在您的conf 文件传递​​参数中使用params 对象,并在您的测试或命令行中的任何位置访问它们。

params: {
     primaryBrowser: 'chrome'  // I am biased towards chrome :)
     secondaryBrowser: 'firefox'
 },

您可以通过使用浏览器的全局对象在测试中访问它们 -

console.log(browser.params.primaryBrowser);
console.log(browser.params.secondaryBrowser);

同样,您可以在命令行中更改它们-

protractor config.js --params.primaryBrowser='firefox'

通过getMultiCapabilities,还有一种更优雅的方式来做这些事情-

您甚至可以通过访问上述函数对象来传递多个浏览器,请参阅此链接了解更多详细信息。

Is there any way to pass multiple browser via protractor cli

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-09
    • 2022-07-21
    • 1970-01-01
    • 1970-01-01
    • 2022-10-23
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    相关资源
    最近更新 更多