1
+ /**
2
+ * The command line interface for interacting with the Protractor runner.
3
+ * It takes care of parsing the config file and command line options.
4
+ */
5
+
1
6
var util = require ( 'util' ) ;
2
7
var path = require ( 'path' )
3
8
var fs = require ( 'fs' ) ;
4
9
var runner = require ( './runner.js' ) ;
5
- var glob = require ( 'glob' ) ;
10
+ var argv = require ( 'optimist' ) .
11
+ usage ( 'Usage: protractor [options] [config]' ) .
12
+ describe ( 'version' , 'Print Protractor version' ) .
13
+ describe ( 'browser' , 'Browsername, e.g. chrome or firefox' ) .
14
+ describe ( 'seleniumAddress' , 'A running seleium address to use' ) .
15
+ describe ( 'seleniumServerJar' , 'Location of the standalone selenium jar file' ) .
16
+ describe ( 'seleniumPort' , 'Optional port for the selenium standalone server' ) .
17
+ describe ( 'baseUrl' , 'URL to prepend to all relative paths' ) .
18
+ describe ( 'rootElement' , 'Element housing ng-app, if not html or body' ) .
19
+ describe ( 'specs' , 'Comma-separated list of files to test' ) .
20
+ describe ( 'verbose' , 'Print full spec names' ) .
21
+ describe ( 'includeStackTrace' , 'Print stack trace on error' ) .
22
+ describe ( 'params' , 'Param object to be passed to the tests' ) .
23
+ alias ( 'browser' , 'capabilities.browserName' ) .
24
+ alias ( 'name' , 'capabilities.name' ) .
25
+ alias ( 'platform' , 'capabilities.platform' ) .
26
+ alias ( 'platform-version' , 'capabilities.version' ) .
27
+ alias ( 'tags' , 'capabilities.tags' ) .
28
+ alias ( 'build' , 'capabilities.build' ) .
29
+ boolean ( 'verbose' ) .
30
+ boolean ( 'includeStackTrace' ) .
31
+ alias ( 'verbose' , 'jasmineNodeOpts.verbose' ) .
32
+ alias ( 'includeStackTrace' , 'jasmineNodeOpts.includeStackTrace' ) .
33
+ check ( function ( arg ) {
34
+ if ( arg . _ . length > 1 ) {
35
+ throw 'Error: more than one config file specified'
36
+ }
37
+ if ( ! ( process . argv . length > 2 ) ) {
38
+ throw '' ;
39
+ }
40
+ } ) .
41
+ argv ;
6
42
7
- /**
8
- * The command line interface for interacting with the Protractor runner.
9
- * It takes care of parsing the config file and command line options.
10
- */
11
43
12
- var args = process . argv . slice ( 2 ) ;
13
44
var configPath ;
14
45
15
46
@@ -19,101 +50,24 @@ var printVersion = function () {
19
50
process . exit ( 0 ) ;
20
51
} ;
21
52
22
-
23
- if ( ! args . length ) {
24
- util . puts ( 'USAGE: protractor [configFile] [options]' ) ;
25
- util . puts ( 'Options:' ) ;
26
- util . puts ( ' --version: Print Protractor version' ) ;
27
- util . puts ( ' --browser <string>: Browsername, e.g. chrome or firefox' ) ;
28
- util . puts ( ' --seleniumAddress <string>: A running selenium address to use' ) ;
29
- util . puts ( ' --seleniumServerJar <string>: Location of the standalone selenium server .jar file' ) ;
30
- util . puts ( ' --seleniumPort <string>: Optional port for the standalone selenium server' ) ;
31
- util . puts ( ' --baseUrl <string>: URL to prepend to all relative paths' ) ;
32
- util . puts ( ' --rootElement <string>: Element housing ng-app, if not html or body' ) ;
33
- util . puts ( ' --specs <list>: Comma separated list of files to test' ) ;
34
- util . puts ( ' --[no]includeStackTrace: Print stack trace on error' ) ;
35
- util . puts ( ' --verbose: Print full spec names' ) ;
36
-
37
- process . exit ( 0 ) ;
53
+ if ( argv . version ) {
54
+ printVersion ( ) ;
38
55
}
39
56
40
- var commandLineConfig = { capabilities : { } , jasmineNodeOpts : { } } ;
41
-
42
- while ( args . length ) {
43
- var arg = args . shift ( ) ;
44
- switch ( arg ) {
45
- case '--version' :
46
- printVersion ( ) ;
47
- break ;
48
- case '--browser' :
49
- commandLineConfig . capabilities . browserName = args . shift ( ) ;
50
- break ;
51
- case '--name' :
52
- commandLineConfig . capabilities . name = args . shift ( ) ;
53
- break ;
54
- case '--platform' :
55
- commandLineConfig . capabilities . platform = args . shift ( ) ;
56
- break ;
57
- case '--platform-version' :
58
- commandLineConfig . capabilities . version = args . shift ( ) ;
59
- break ;
60
- case '--build' :
61
- commandLineConfig . capabilities . build = args . shift ( ) ;
62
- break ;
63
- case '--tags' :
64
- commandLineConfig . capabilities . tags = args . shift ( ) . split ( ',' ) ;
65
- break ;
66
- case '--seleniumAddress' :
67
- commandLineConfig . seleniumAddress = args . shift ( ) ;
68
- break ;
69
- case '--seleniumServerJar' :
70
- commandLineConfig . seleniumServerJar = args . shift ( ) ;
71
- break ;
72
- case '--seleniumPort' :
73
- commandLineConfig . seleniumPort = args . shift ( ) ;
74
- break ;
75
- case '--chromeDriver' :
76
- commandLineConfig . chromeDriver = args . shift ( ) ;
77
- break ;
78
- case '--sauceUser' :
79
- commandLineConfig . sauceUser = args . shift ( ) ;
80
- break ;
81
- case '--sauceKey' :
82
- commandLineConfig . sauceKey = args . shift ( ) ;
83
- break ;
84
- case '--baseUrl' :
85
- commandLineConfig . baseUrl = args . shift ( ) ;
86
- break ;
87
- case '--rootElement' :
88
- commandLineConfig . rootElement = args . shift ( ) ;
89
- break ;
90
- case '--specs' :
91
- commandLineSpecs = args . shift ( ) . split ( ',' ) ;
92
- commandLineSpecs . forEach ( function ( spec , index , arr ) {
93
- arr [ index ] = path . resolve ( process . cwd ( ) , spec ) ;
94
- } ) ;
95
- commandLineConfig . specs = commandLineSpecs ;
96
- break ;
97
- case '--includeStackTrace' :
98
- commandLineConfig . jasmineNodeOpts . includeStackTrace = true ;
99
- break ;
100
- case '--noincludeStackTrace' :
101
- commandLineConfig . jasmineNodeOpts . includeStackTrace = false ;
102
- break ;
103
- case '--verbose' :
104
- commandLineConfig . jasmineNodeOpts . isVerbose = true ;
105
- break ;
106
- default :
107
- configPath = path . resolve ( process . cwd ( ) , arg ) ;
108
- break ;
109
- }
57
+ if ( argv . specs ) {
58
+ argv . specs = argv . specs . split ( ',' ) ;
59
+ argv . specs . forEach ( function ( spec , index , arr ) {
60
+ arr [ index ] = path . resolve ( process . cwd ( ) , spec ) ;
61
+ } ) ;
110
62
}
111
63
112
- if ( configPath ) {
64
+ var configFilename = argv . _ [ 0 ] ;
65
+ if ( configFilename ) {
66
+ configPath = path . resolve ( process . cwd ( ) , configFilename ) ;
113
67
runner . addConfig ( require ( configPath ) . config ) ;
114
68
runner . addConfig ( { specFileBase : path . dirname ( configPath ) } )
115
69
}
116
70
117
- runner . addConfig ( commandLineConfig ) ;
71
+ runner . addConfig ( argv ) ;
118
72
119
73
runner . runOnce ( ) ;
0 commit comments