forked from angular/protractor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
129 lines (117 loc) · 3.92 KB
/
cli.js
File metadata and controls
129 lines (117 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* The command line interface for interacting with the Protractor runner.
* It takes care of parsing command line options.
*
* Values from command line options override values from the config.
*/
'use strict';
var args = [];
process.argv.slice(2).forEach(function(arg) {
var flag = arg.split('=')[0];
switch (flag) {
case 'debug':
args.push('--nodeDebug');
args.push('true');
break;
case '-d':
case '--debug':
case '--debug-brk':
args.push('--v8Debug');
args.push('true');
break;
default:
args.push(arg);
break;
}
});
var util = require('util');
var path = require('path');
var fs = require('fs');
var optimist = require('optimist').
usage('Usage: protractor [options] [configFile]\n' +
'configFile defaults to protractor.conf.js\n' +
'The [options] object will override values from the config file.\n' +
'See the reference config for a full list of options.').
describe('help', 'Print Protractor help menu').
describe('version', 'Print Protractor version').
describe('browser', 'Browsername, e.g. chrome or firefox').
describe('seleniumAddress', 'A running seleium address to use').
describe('seleniumServerJar', 'Location of the standalone selenium jar file').
describe('seleniumPort', 'Optional port for the selenium standalone server').
describe('baseUrl', 'URL to prepend to all relative paths').
describe('rootElement', 'Element housing ng-app, if not html or body').
describe('specs', 'Comma-separated list of files to test').
describe('exclude', 'Comma-separated list of files to exclude').
describe('verbose', 'Print full spec names').
describe('stackTrace', 'Print stack trace on error').
describe('params', 'Param object to be passed to the tests').
describe('framework', 'Test framework to use: jasmine, cucumber or mocha').
alias('browser', 'capabilities.browserName').
alias('name', 'capabilities.name').
alias('platform', 'capabilities.platform').
alias('platform-version', 'capabilities.version').
alias('tags', 'capabilities.tags').
alias('build', 'capabilities.build').
alias('verbose', 'jasmineNodeOpts.isVerbose').
alias('stackTrace', 'jasmineNodeOpts.includeStackTrace').
string('capabilities.tunnel-identifier').
check(function(arg) {
if (arg._.length > 1) {
throw 'Error: more than one config file specified';
}
});
var argv = optimist.parse(args);
if (argv.version) {
util.puts('Version ' + require(path.join(__dirname, '../package.json')).version);
process.exit(0);
}
// WebDriver capabilities properties require dot notation, but optimist parses
// that into an object. Re-flatten it.
var flattenObject = function(obj) {
var prefix = arguments[1] || '';
var out = arguments[2] || {};
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
typeof obj[prop] === 'object' ?
flattenObject(obj[prop], prefix + prop + '.', out) :
out[prefix + prop] = obj[prop];
}
}
return out;
};
if (argv.capabilities) {
argv.capabilities = flattenObject(argv.capabilities);
}
/**
* Helper to resolve comma separated lists of file pattern strings relative to
* the cwd.
*
* @private
* @param {Array} list
*/
var processFilePatterns_ = function(list) {
var patterns = list.split(',');
patterns.forEach(function(spec, index, arr) {
arr[index] = path.resolve(process.cwd(), spec);
});
return patterns;
};
if (argv.specs) {
argv.specs = processFilePatterns_(argv.specs);
}
if (argv.exclude) {
argv.exclude = processFilePatterns_(argv.exclude);
}
// Use default configuration, if it exists.
var configFile = argv._[0];
if (!configFile) {
if (fs.existsSync('./protractor.conf.js')) {
configFile = './protractor.conf.js';
}
}
if (!configFile && args.length < 3) {
optimist.showHelp();
process.exit(1);
}
// Run the launcher
require('./launcher').init(configFile, argv);