Is there any way to pass multiple browser via protractor cli

前端 未结 3 410
旧时难觅i
旧时难觅i 2020-12-31 19:29

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

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

相关标签:
3条回答
  • 2020-12-31 20:09

    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();
    },
    
    0 讨论(0)
  • 2020-12-31 20:27

    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.

    0 讨论(0)
  • 2020-12-31 20:32

    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.

    0 讨论(0)
提交回复
热议问题