@@ -120,6 +120,31 @@ var setUpSelenium = function() {
120
120
} ) ;
121
121
}
122
122
123
+ var defaultChromedriver ;
124
+ if ( config . chromeDriver ) {
125
+ if ( ! fs . existsSync ( config . chromeDriver ) ) {
126
+ if ( fs . existsSync ( config . chromeDriver + '.exe' ) ) {
127
+ config . chromeDriver += '.exe' ;
128
+ } else {
129
+ throw 'Could not find chromedriver at ' + config . chromeDriver ;
130
+ }
131
+ }
132
+ } else {
133
+ defaultChromedriver = path . resolve ( __dirname ,
134
+ '../selenium/chromedriver' ) ;
135
+ if ( fs . existsSync ( defaultChromedriver ) ) {
136
+ config . chromeDriver = defaultChromedriver ;
137
+ } else if ( fs . existsSync ( defaultChromedriver + '.exe' ) ) {
138
+ config . chromeDriver = defaultChromedriver + '.exe' ;
139
+ }
140
+ }
141
+
142
+ // Priority
143
+ // 1) if chromeOnly, use that
144
+ // 2) if seleniumAddress is given, use that
145
+ // 3) if a sauceAccount is given, use that.
146
+ // 4) if a seleniumServerJar is specified, use that
147
+ // 5) try to find the seleniumServerJar in protractor/selenium
123
148
if ( config . chromeOnly ) {
124
149
util . puts ( 'Using ChromeDriver directly...' ) ;
125
150
deferred . fulfill ( null ) ;
@@ -137,23 +162,29 @@ var setUpSelenium = function() {
137
162
138
163
util . puts ( 'Using SauceLabs selenium server at ' + config . seleniumAddress ) ;
139
164
deferred . fulfill ( config . seleniumAddress ) ;
140
- } else if ( config . seleniumServerJar ) {
165
+ } else {
141
166
util . puts ( 'Starting selenium standalone server...' ) ;
142
- if ( config . chromeDriver ) {
143
- if ( ! fs . existsSync ( config . chromeDriver ) ) {
144
- if ( fs . existsSync ( config . chromeDriver + '.exe' ) ) {
145
- config . chromeDriver += '.exe' ;
146
- } else {
147
- throw 'Could not find chromedriver at ' + config . chromeDriver ;
148
- }
167
+
168
+ if ( ! config . seleniumServerJar ) {
169
+ // Try to use the default location.
170
+ var defaultStandalone = path . resolve ( __dirname ,
171
+ '../selenium/selenium-server-standalone-' +
172
+ require ( '../package.json' ) . webdriverVersions . selenium + '.jar' ) ;
173
+ if ( ! fs . existsSync ( defaultStandalone ) ) {
174
+ throw new Error ( 'Unable to start selenium. ' +
175
+ 'You must specify either a seleniumAddress, ' +
176
+ 'seleniumServerJar, or saucelabs account, or use webdriver-manager.' ) ;
177
+ } else {
178
+ config . seleniumServerJar = defaultStandalone ;
149
179
}
150
- config . seleniumArgs . push (
151
- '-Dwebdriver.chrome.driver=' + config . chromeDriver ) ;
180
+ } else if ( ! fs . existsSync ( config . seleniumServerJar ) ) {
181
+ throw new Error ( 'there\'s no selenium server jar at the specified ' +
182
+ 'location. Do you have the correct version?' ) ;
152
183
}
153
184
154
- if ( config . seleniumServerJar && ! fs . existsSync ( config . seleniumServerJar ) ) {
155
- throw new Error ( 'there\'s no selenium server jar at the specified location.' +
156
- 'Do you have the correct version?' ) ;
185
+ if ( config . chromeDriver ) {
186
+ config . seleniumArgs . push (
187
+ '-Dwebdriver.chrome.driver=' + config . chromeDriver ) ;
157
188
}
158
189
159
190
server = new remote . SeleniumServer ( config . seleniumServerJar , {
@@ -166,9 +197,6 @@ var setUpSelenium = function() {
166
197
config . seleniumAddress = server . address ( ) ;
167
198
deferred . fulfill ( config . seleniumAddress ) ;
168
199
} ) ;
169
- } else {
170
- throw new Error ( 'You must specify either a seleniumAddress, ' +
171
- 'seleniumServerJar, or saucelabs account.' ) ;
172
200
}
173
201
174
202
return deferred . promise ;
@@ -210,13 +238,6 @@ var runJasmineTests = function() {
210
238
var runDeferred = webdriver . promise . defer ( ) ;
211
239
212
240
if ( config . chromeOnly ) {
213
- if ( ! fs . existsSync ( config . chromeDriver ) ) {
214
- if ( fs . existsSync ( config . chromeDriver + '.exe' ) ) {
215
- config . chromeDriver += '.exe' ;
216
- } else {
217
- throw 'Could not find chromedriver at ' + config . chromeDriver ;
218
- }
219
- }
220
241
var service = new chrome . ServiceBuilder ( config . chromeDriver ) . build ( ) ;
221
242
driver = chrome . createDriver (
222
243
new webdriver . Capabilities ( config . capabilities ) , service ) ;
0 commit comments