I start my protractor tests by running the following:
protractor protractor.conf.js --params.baseUrl=http://www.google.com --suite all
I w
Here is a sample code to iterate thru cmd line args in your Protractor config file and set specs (and some other run configuration values) directly from command line:
config.js
// usage: protractor config.js --params.specs="*" --params.browser=ie --params.threads=1
// protractor config.js --params.specs="dir1|dir2"
// protractor config.js --params.specs="dir1|dir2/spec1.js|dir2/spec2.js"
// process command line arguments and initialize run configuration file
var init = function(config) {
const path = require('path');
var specs;
for (var i = 3; i < process.argv.length; i++) {
var match = process.argv[i].match(/^--params\.([^=]+)=(.*)$/);
if (match)
switch (match[1]) {
case 'specs':
specs = match[2];
break;
case 'browser':
config.capabilities.browserName = match[2];
if (match[2].toLowerCase() === 'ie') {
config.capabilities.browserName = 'internet explorer';
config.capabilities.platform = 'ANY';
config.capabilities.version = '11';
config.seleniumArgs = ['-Dwebdriver.ie.driver=' + path.join('node_modules', 'protractor' ,'selenium' ,'IEDriverServer.exe')];
}
if (match[2] !== 'chrome' && match[2] !== 'firefox')
config.directConnect = false;
break;
case 'timeout':
config.jasmineNodeOpts.defaultTimeoutInterval = parseInt(match[2]);
break;
case 'threads':
config.capabilities.maxInstances = parseInt(match[2]);
config.capabilities.shardTestFiles = config.capabilities.maxInstances > 1;
break;
}
}
// generate specs array
specs.split(/\|/g).forEach(function(dir) {
if (dir.endsWith('.js'))
config.specs.push(dir);
else
config.specs.push(path.join(dir, '*.js'));
});
return config;
};
exports.config = (function() {
return init({
specs: [],
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 300000 // 5 min
},
capabilities: {
browserName: 'chrome',
shardTestFiles: false,
maxInstances: 1
},
directConnect: true
});
})();
In case you need every single item in the entire configuration file, you can use browser.getProcessedConfig()
to do this.
onPrepare: () => {
browser.getProcessedConfig().then(console.log); // even `params` is in here
}
I am not completely sure if protractor globals are set at the beforeLaunch()
stage, but they are definitely available at onPrepare()
step.
Access the params
object through the global browser
object:
console.log(browser.params.baseUrl);
Update:
Using Jasmine 2.6+, protractor 4.x, browser.params was empty, but the following worked in onPrepare()
step:
console.log(browser.baseUrl);