@@ -168,20 +168,23 @@ function importSupportObjects() {
168168 global . helpers = require ( '../runtime/helpers.js' ) ;
169169}
170170
171- function teardownBrowser ( driver ) {
171+ function closeBrowser ( ) {
172+ // firefox quits on driver.close on the last window
173+ return driver . close ( ) . then ( function ( ) {
174+ if ( browserName !== 'firefox' ) {
175+ return driver . quit ( ) ;
176+ }
177+ } ) ;
178+ }
179+
180+ function teardownBrowser ( ) {
172181 switch ( browserTeardownStrategy ) {
173182 case 'none' :
174- return new Promise (
175- function ( resolve , reject ) { } ) ;
183+ return Promise . resolve ( ) ;
176184 case 'clear' :
177- return driver . manage ( ) . deleteAllCookies ( ) ;
185+ return helpers . clearCookiesAndStorages ( ) ;
178186 default :
179- // firefox quits on driver.close on the last window
180- return driver . close ( ) . then ( function ( ) {
181- if ( browserName !== 'firefox' ) {
182- return driver . quit ( ) ;
183- }
184- } ) ;
187+ return closeBrowser ( driver ) ;
185188 }
186189}
187190
@@ -235,18 +238,11 @@ module.exports = function () {
235238 fs . writeFileSync ( junitOutputPath , xmlReport ) ;
236239 }
237240
238- console . log ( browserTeardownStrategy ) ;
239-
240241 if ( browserTeardownStrategy !== 'always' ) {
241- driver . close ( ) . then ( function ( ) {
242- if ( browserName !== 'firefox' ) {
243- return driver . quit ( ) ;
244- }
245- done ( ) ;
246- } ) ;
242+ closeBrowser ( ) . then ( ( ) => done ( ) ) ;
247243 }
248244 else {
249- done ( ) ;
245+ new Promise ( ( ) => { } ) . then ( ( ) => done ( ) ) ;
250246 }
251247 } ) ;
252248
@@ -258,16 +254,14 @@ module.exports = function () {
258254
259255 scenario . attach ( new Buffer ( screenShot , 'base64' ) , 'image/png' ) ;
260256
261- teardownBrowser ( driver ) . then ( function ( ) {
257+ return teardownBrowser ( ) . then ( function ( ) {
262258 if ( eyes ) {
263259 // If the test was aborted before eyes.close was called ends the test as aborted.
264260 return eyes . abortIfNotClosed ( ) ;
265261 }
266-
267- return Promise . resolve ( ) ;
268262 } ) ;
269263 } ) ;
270264 }
271- return teardownBrowser ( driver ) ;
265+ return teardownBrowser ( ) ;
272266 } ) ;
273267} ;
0 commit comments