Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
Improving the command line interface (adding more options). This allows
Browse files Browse the repository at this point in the history
the --spec option to be passed with test files that will be resolved
relative to the current directory. Smarter merging of default config
values. Closes #65.
  • Loading branch information
juliemr committed Sep 5, 2013
1 parent cfc6438 commit 9f53118
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 17 deletions.
65 changes: 56 additions & 9 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ var glob = require('glob');
var args = process.argv.slice(2);
var configDir;

var merge = function(into, from) {
for (key in from) {
if (into[key] instanceof Object) {
merge(into[key], from[key]);
} else {
into[key] = from[key];
}
}
};

// Default configuration.
var config = {
seleniumServerJar: null,
Expand All @@ -22,7 +32,6 @@ var config = {
},
rootElement: 'body',
jasmineNodeOpts: {
specs: [],
isVerbose: false,
showColors: true,
includeStackTrace: true
Expand Down Expand Up @@ -70,6 +79,8 @@ var printVersion = function () {
};

var run = function() {
util.puts(util.inspect(config));
process.exit(0);
if (config.jasmineNodeOpts.specFolders) {
throw new Error('Using config.jasmineNodeOpts.specFolders is deprecated ' +
'in Protractor 0.6.0. Please switch to config.specs.');
Expand Down Expand Up @@ -160,34 +171,70 @@ if (!args.length) {
util.puts('USAGE: protractor configFile [options]');
util.puts('Options:');
util.puts(' --version: Print Protractor version');
util.puts(' --seleniumAddress: A running selenium address to use');
util.puts(' --seleniumServerJar: Location of the standalone selenium server .jar file');
util.puts(' --seleniumPort: Optional port for the standalone selenium server');
util.puts(' --seleniumAddress <string>: A running selenium address to use');
util.puts(' --seleniumServerJar <string>: Location of the standalone selenium server .jar file');
util.puts(' --seleniumPort <string>: Optional port for the standalone selenium server');
util.puts(' --baseUrl <string>: URL to prepend to all relative paths');
util.puts(' --rootElement <string>: Element housing ng-app, if not html or body');
util.puts(' --specs <list>: Comma separated list of files to test');
util.puts(' --[no]includeStackTrace: Print stack trace on error');
util.puts(' --verbose: Print full spec names');

process.exit(0);
}

var commandLineConfig = { capabilities: {}, jasmineNodeOpts: {}};

while(args.length) {
var arg = args.shift();
switch(arg) {
case '--version':
printVersion();
break;
case '--browser':
config.capabilities.browserName = args.shift();
commandLineConfig.capabilities.browserName = args.shift();
break;
case '--seleniumAddress':
config.seleniumAddress = args.shift();
commandLineConfig.seleniumAddress = args.shift();
break;
case '--seleniumServerJar':
config.seleniumServerJar = args.shift();
commandLineConfig.seleniumServerJar = args.shift();
break;
case '--seleniumPort':
config.seleniumPort = args.shift();
commandLineConfig.seleniumPort = args.shift();
break;
case '--sauceUser':
commandLineConfig.sauceUser = args.shift();
break;
case '--sauceKey':
commandLineConfig.sauceKey = args.shift();
break;
case '--baseUrl':
commandLineConfig.baseUrl = args.shift();
break;
case '--rootElement':
commandLineConfig.rootElement = args.shift();
break;
case '--specs':
commandLineSpecs = args.shift().split(',');
commandLineSpecs.forEach(function(spec, index, arr) {
arr[index] = path.resolve(process.cwd(), spec);
});
commandLineConfig.specs = commandLineSpecs;
break;
case '--includeStackTrace':
commandLineConfig.jasmineNodeOpts.includeStackTrace = true;
break;
case '--noincludeStackTrace':
commandLineConfig.jasmineNodeOpts.includeStackTrace = false;
break;
case '--verbose':
commandLineConfig.jasmineNodeOpts.isVerbose = true;
break;
default:
var configPath = path.resolve(process.cwd(), arg);
config = require(configPath).config;
merge(config, require(configPath).config);
merge (config, commandLineConfig);
configDir = path.dirname(configPath);
break;
}
Expand Down
9 changes: 1 addition & 8 deletions spec/basicConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@ exports.config = {

// Spec patterns are relative to this directory.
specs: [
'*_spec.js',
'*_spec.js'
],

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

baseUrl: 'http://localhost:8000',

jasmineNodeOpts: {
onComplete: null,
isVerbose: false,
showColors: true,
includeStackTrace: true,
}
};

0 comments on commit 9f53118

Please sign in to comment.