Is there any way to pass multiple browser via protractor cli

不问归期 提交于 2020-01-10 14:59:17

问题


Just wanted to know is it possible to specify cli args to protractor like

--multiCapabilities.0.browserName chrome --multiCapabilities.1.browserName firefox

so that it overrides the multiCapabilities defined in protractor conf file.


回答1:


A concrete example of Isaac Lyman's first suggestion:

CLI:

protractor ... --params.browsers="chrome,firefox"

conf.js:

var capabilities = {
  chrome: {
    browserName: 'chrome'
  },

  firefox: {
    browserName: 'firefox'
  }
};

...

getMultiCapabilities: function() {
  var browsers = this.params.browsers.split(',');

  // Using lodash to select the keys in `capabilities` corresponding 
  // to the browsers param.
  return _( capabilities )
    .pick(browsers)
    .values()
    .value();
},



回答2:


There are a couple of things you could try.

How can I use command line arguments in Angularjs Protractor? explains how to pass in a "params" variable, which if you were totally pro you could reference later in the config file, with the multiCapabilities section (maybe use a helper function or an if statement so you don't have to pass in a complex object from the command line). Not easy to do, but possible.

https://sourcegraph.com/github.com/teerapap/grunt-protractor-runner (see the Options section) is a utility that lets you pass in these things from the command line without any trouble. It's open-source and seems like it would be easy to mod if it doesn't quite meet your needs.

The easiest option, assuming you just need a couple of different options, would just be to use two different config files, "protractor.chrome.conf.js" and "protractor.firefox.conf.js" and run whichever one you need at the moment.




回答3:


This is a reasonable request. I've created a PR for this here: https://github.com/angular/protractor/pull/1770. For now, you can patch this PR to your local protractor to use this feature.



来源:https://stackoverflow.com/questions/28239378/is-there-any-way-to-pass-multiple-browser-via-protractor-cli

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!