1

I am running my Protractor Test from command npm run e2e

I want a way so that if I pass npm run e2e firefox then my test will get executed on Firefox browser.

Or if I run npm run e2e chrome then it should run on chrome

if I pass both npm run e2e firefox chrome then my test should run on both the browser in parallel.

Is it possible to parametrize protractor config file?

Similarly if I can pass test suite name via command and it should execute only tests under that particular test suite.

Here is my config file and this is what I want to achieve:

`//var HtmlReporter = require('protractor-html-screenshot-reporter');

exports.config = {

allScriptsTimeout: 30000,
//Add parameters for browser names
params:{
  pass: {
      browserName : 'chrome',
      testSuitName : 'e2e/TestSuites/_BVT/*.js',
  }
 },  
suites: {    
//Define here List of Sanity Test Scenarios:
  BVT : testSuitName,   
}, 
// configure multiple browsers to run tests
multiCapabilities: [
 shardTestFiles: true,
 maxInstances: 2   
{'browserName': browserName}
],
baseUrl: 'http://mytestUrl/',
 framework: 'jasmine2',
jasmineNodeOpts: {
 defaultTimeoutInterval: 30000
},  
onPrepare: function() {  
var jasmineReporters = require('jasmine-reporters');
browser.driver.manage().window().maximize();
return browser.getProcessedConfig().then(function(config) {   
  var browserName = config.capabilities.browserName;
  var junitReporter = new jasmineReporters.JUnitXmlReporter({
         consolidateAll: true,
         savePath: 'tests/test-results',            
         filePrefix: browserName + '-xmloutput',
         modifySuiteName: function(generatedSuiteName, suite) {             
             return browserName + '.' + generatedSuiteName;
         }              
     });
     jasmine.getEnv().addReporter(junitReporter);
  });    
}, 
resultJsonOutputFile: 'tests/test-results/output.json'    
};`

Would appreciate any help on this.
Thanks in advance.

ssharma
  • 935
  • 2
  • 19
  • 43
  • did you tried `capabilities: { 'browserName': 'chrome' },` in your spec file? that will allow you to choose your browser. – Mohamed NAOUALI May 11 '16 at 21:19
  • yes I did tried, but I want to parametrize browserName : $param value so that I can pass this value from command line and config file will take this value either chrome or firefox or IE.. – ssharma May 11 '16 at 21:37
  • would you have a look to this link http://stackoverflow.com/questions/23135649/how-can-i-use-command-line-arguments-in-angularjs-protractor and the referenceConf.js link https://github.com/angular/protractor/blob/master/docs/referenceConf.js you can use params to do that – Mohamed NAOUALI May 11 '16 at 21:54
  • @MohamedNAOUALI this shows how can I pass parameters like username, pwd etc to config and use it in my test. But I want my browser value and test suite values to be parametrize. I want my config file to look something like: capabilities: { 'browserName': param1 }, and suites: { Test1: param2 }, and when I execute `npm run e2e 'chrome' 'logintest.js'` command my logintest.js should get executed on chrome browser. Is it possible to achieve this? – ssharma May 12 '16 at 05:14
  • any idea on this how can I achieve this? – ssharma May 12 '16 at 18:22

3 Answers3

5

I know this post is a bit old now, but this solution may help people having a similar problem.

Use multiple config files, one for each browser type, setup a base config file, and require that into each of the other config files, and then create an npm script for each config file. No need for parameters and everything stacks nicely.

so the base config (called something like "protractor_base.js")would look something like:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  rootElement: '[ng-app]',

  allScriptsTimeout: 60000,

  framework: 'jasmine',

  specs: ['example-spec.js']
};

And then your other configs (ie "protractor_chrome.conf.js") would look something like:

protractor = require('./protractor_base.js');
var config = protractor.config;

config.capabilities: {
  'browserName': 'chrome'
};


exports.config = config;

You can then specify a multi browser config, just a chrome one, etc.

user3075259
  • 315
  • 2
  • 15
1
--capabilities.chromeOptions.args=headless --capabilities.chromeOptions.args=disable-gpu --capabilities.chromeOptions.args=window-size=1200,600

The above code should work for you.

Kevin Ghadyani
  • 6,829
  • 6
  • 44
  • 62
0

I was looking for passing parameters from command line to protractor config file and found a way to do this:

npm run e2e -- --baseUrl=http://testurl:8080 --suite=suite_name_defined_in_config --capabilities.browserName=browser_Name

where my npm package.json :

 "e2e": "protractor tests/protractor-conf.js",

and config file contains :

suites: {
    BVT: 'e2e/TestSuites/_BVT/*.js',
    Full: 'e2e/TestSuites/Full/**/*.js',      
},
capabilities: {
  'browserName': 'chrome'
},
baseUrl: 'http://localhost:8080/',  
ssharma
  • 935
  • 2
  • 19
  • 43
  • 1
    If I have a capabilities value which is an array, what is the correct way to pass it as a parameter? For example (that not works): `--capabilities.chromeOptions.args = ["--headless", "--disable-gpu", "--window-size=800x600"]` – Eduardo Baitello Sep 28 '17 at 15:09