@@ -24,7 +24,6 @@ var Runner = function(config) {
24
24
this . preparer_ = null ;
25
25
this . driverprovider_ = null ;
26
26
this . config_ = config ;
27
- this . drivers_ = [ ] ;
28
27
29
28
if ( config . v8Debug ) {
30
29
// Call this private function instead of sending SIGUSR1 because Windows.
@@ -147,13 +146,13 @@ Runner.prototype.controlFlow = function() {
147
146
* Sets up convenience globals for test specs
148
147
* @private
149
148
*/
150
- Runner . prototype . setupGlobals_ = function ( browser ) {
149
+ Runner . prototype . setupGlobals_ = function ( browser_ ) {
151
150
// Export protractor to the global namespace to be used in tests.
152
151
global . protractor = protractor ;
153
- global . browser = browser ;
154
- global . $ = browser . $ ;
155
- global . $$ = browser . $$ ;
156
- global . element = browser . element ;
152
+ global . browser = browser_ ;
153
+ global . $ = browser_ . $ ;
154
+ global . $$ = browser_ . $$ ;
155
+ global . element = browser_ . element ;
157
156
global . by = global . By = protractor . By ;
158
157
159
158
// Enable sourcemap support for stack traces.
@@ -176,13 +175,12 @@ Runner.prototype.setupGlobals_ = function(browser) {
176
175
Runner . prototype . createBrowser = function ( ) {
177
176
var config = this . config_ ;
178
177
var driver = this . driverprovider_ . getNewDriver ( ) ;
179
- this . drivers_ . push ( driver ) ;
180
178
driver . manage ( ) . timeouts ( ) . setScriptTimeout ( config . allScriptsTimeout ) ;
181
- var browser = protractor . wrapDriver ( driver ,
179
+ var browser_ = protractor . wrapDriver ( driver ,
182
180
config . baseUrl , config . rootElement ) ;
183
- browser . params = config . params ;
181
+ browser_ . params = config . params ;
184
182
if ( config . getPageTimeout ) {
185
- browser . getPageTimeout = config . getPageTimeout ;
183
+ browser_ . getPageTimeout = config . getPageTimeout ;
186
184
}
187
185
var self = this ;
188
186
@@ -193,45 +191,34 @@ Runner.prototype.createBrowser = function() {
193
191
* @param {boolean } opt_copyMockModules Whether to apply same mock modules on creation
194
192
* @return {Protractor } a protractor instance.
195
193
*/
196
- browser . forkNewDriverInstance = function ( opt_useSameUrl , opt_copyMockModules ) {
194
+ browser_ . forkNewDriverInstance = function ( opt_useSameUrl , opt_copyMockModules ) {
197
195
var newBrowser = self . createBrowser ( ) ;
198
196
if ( opt_copyMockModules ) {
199
- newBrowser . mockModules_ = browser . mockModules_ ;
197
+ newBrowser . mockModules_ = browser_ . mockModules_ ;
200
198
}
201
199
if ( opt_useSameUrl ) {
202
- browser . driver . getCurrentUrl ( ) . then ( function ( url ) {
200
+ browser_ . driver . getCurrentUrl ( ) . then ( function ( url ) {
203
201
newBrowser . get ( url ) ;
204
202
} ) ;
205
203
}
206
204
return newBrowser ;
207
205
} ;
208
- return browser ;
206
+ return browser_ ;
209
207
} ;
210
208
209
+
211
210
/**
212
211
* Final cleanup on exiting the runner.
213
212
*
214
213
* @return {q.Promise } A promise which resolves on finish.
215
214
* @private
216
215
*/
217
216
Runner . prototype . shutdown_ = function ( ) {
218
- var deferredArr = this . drivers_ . map ( function ( driver ) {
219
- var deferred = q . defer ( ) ;
220
- driver . getSession ( ) . then ( function ( session_ ) {
221
- if ( session_ ) {
222
- driver . quit ( ) . then ( function ( ) {
223
- deferred . resolve ( ) ;
224
- } ) ;
225
- } else {
226
- deferred . resolve ( ) ;
227
- }
228
- } ) ;
229
- return deferred . promise ;
230
- } ) ;
231
- return q . all ( deferredArr ) ;
217
+ return q . all (
218
+ this . driverprovider_ . getExistingDrivers ( ) .
219
+ map ( this . driverprovider_ . quitDriver . bind ( this . driverprovider_ ) ) ) ;
232
220
} ;
233
221
234
-
235
222
/**
236
223
* The primary workhorse interface. Kicks off the test running process.
237
224
*
@@ -241,7 +228,8 @@ Runner.prototype.shutdown_ = function() {
241
228
Runner . prototype . run = function ( ) {
242
229
var self = this ,
243
230
testPassed ,
244
- plugins ;
231
+ plugins ,
232
+ browser_ ;
245
233
246
234
if ( ! this . config_ . specs . length ) {
247
235
throw new Error ( 'Spec patterns did not match any files.' ) ;
@@ -256,9 +244,9 @@ Runner.prototype.run = function() {
256
244
} ) ;
257
245
// 2) Create a browser and setup globals
258
246
} ) . then ( function ( ) {
259
- var browser = self . createBrowser ( ) ;
260
- self . setupGlobals_ ( browser ) ;
261
- return browser . getSession ( ) . then ( function ( session ) {
247
+ browser_ = self . createBrowser ( ) ;
248
+ self . setupGlobals_ ( browser_ ) ;
249
+ return browser_ . getSession ( ) . then ( function ( session ) {
262
250
log . debug ( 'WebDriver session successfully started with capabilities ' +
263
251
util . inspect ( session . getCapabilities ( ) ) ) ;
264
252
} , function ( err ) {
@@ -287,6 +275,20 @@ Runner.prototype.run = function() {
287
275
') is not a valid framework.' ) ;
288
276
}
289
277
278
+ if ( self . config_ . restartBrowserBetweenTests ) {
279
+ var restartDriver = function ( ) {
280
+ // Note: because tests are not paused at this point, any async
281
+ // calls here are not guaranteed to complete before the tests resume.
282
+ self . driverprovider_ . quitDriver ( browser_ . driver ) ;
283
+ // Copy mock modules, but do not navigate to previous URL.
284
+ browser_ = browser_ . forkNewDriverInstance ( false , true ) ;
285
+ self . setupGlobals_ ( browser_ ) ;
286
+ } ;
287
+
288
+ self . on ( 'testPass' , restartDriver ) ;
289
+ self . on ( 'testFail' , restartDriver ) ;
290
+ }
291
+
290
292
return require ( frameworkPath ) . run ( self , self . config_ . specs ) .
291
293
then ( function ( testResults ) {
292
294
return helper . joinTestLogs ( pluginSetupResults , testResults ) ;
0 commit comments