19
19
const fs = require ( 'fs' ) ;
20
20
const os = require ( 'os' ) ;
21
21
const path = require ( 'path' ) ;
22
+ const rimraf = require ( "rimraf" ) ;
22
23
23
24
var SafariBrowser = function ( baseBrowserDecorator ) {
24
25
baseBrowserDecorator ( this ) ;
@@ -33,9 +34,27 @@ var SafariBrowser = function (baseBrowserDecorator) {
33
34
) ;
34
35
const HTML_TRAMPOLINE_PATH = path . join ( SAFARI_DATA_DIR , 'redirect.html' ) ;
35
36
37
+ function clearSafariData ( ) {
38
+ const directoriesToClear = [
39
+ path . join ( SAFARI_DATA_DIR , 'Library/Caches' ) ,
40
+ path . join ( SAFARI_DATA_DIR , 'Library/Cookies' ) ,
41
+ path . join ( SAFARI_DATA_DIR , 'Library/Safari' ) ,
42
+ path . join ( SAFARI_DATA_DIR , 'Library/WebKit' ) ,
43
+ ]
44
+
45
+ directoriesToClear . forEach ( ( dir ) => {
46
+ if ( fs . existsSync ( dir ) ) {
47
+ rimraf . sync ( dir ) ;
48
+ }
49
+ } )
50
+ }
51
+
36
52
this . _start = function ( url ) {
37
53
var self = this ;
38
54
55
+ // Clear cookies and other persisted data before starting the browser
56
+ clearSafariData ( ) ;
57
+
39
58
// HTML trampoline to redirect Safari to the URL where the tests are hosted.
40
59
// This is necessary because Safari assumes the location we pass as an argument is a path
41
60
// in the Safari Data directory. So, if we were to pass 'http://localhost:3000' as an argument,
0 commit comments