Skip to content

Commit 24e9df2

Browse files
committed
fix(selenium): specify a temp user directory
1 parent b83d936 commit 24e9df2

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

selenium/createDriver.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import { browserSupportsHeadless } from "../lib/getBrowserString.js";
88
// Set script timeout to 10min
99
const DRIVER_SCRIPT_TIMEOUT = 1000 * 60 * 10;
1010

11-
export default async function createDriver( { browserName, headless, url, verbose } ) {
11+
export default async function createDriver( {
12+
browserName,
13+
headless,
14+
url,
15+
verbose
16+
} ) {
1217
const capabilities = Capabilities[ browserName ]();
1318

1419
// Support: IE 11+
@@ -23,7 +28,12 @@ export default async function createDriver( { browserName, headless, url, verbos
2328

2429
const chromeOptions = new Chrome.Options();
2530
chromeOptions.addArguments( "--enable-chrome-browser-cloud-management" );
26-
chromeOptions.addArguments( "--no-sandbox" );
31+
32+
// Create temp dir for user data
33+
// to avoid conflicts with other instances
34+
// Use the OS-specific temp dir
35+
const tempDir = process.platform === "win32" ? "C:/Temp" : "/tmp";
36+
chromeOptions.addArguments( `--user-data-dir=${ tempDir }/chrome-user-data` );
2737

2838
// Alter the chrome binary path if
2939
// the CHROME_BIN environment variable is set
@@ -58,7 +68,9 @@ export default async function createDriver( { browserName, headless, url, verbos
5868

5969
const ieOptions = new IE.Options();
6070
ieOptions.setEdgeChromium( true );
61-
ieOptions.setEdgePath( "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe" );
71+
ieOptions.setEdgePath(
72+
"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
73+
);
6274

6375
if ( headless ) {
6476
chromeOptions.addArguments( "--headless=new" );
@@ -72,7 +84,8 @@ export default async function createDriver( { browserName, headless, url, verbos
7284
}
7385
}
7486

75-
const driver = new Builder().withCapabilities( capabilities )
87+
const driver = new Builder()
88+
.withCapabilities( capabilities )
7689
.setChromeOptions( chromeOptions )
7790
.setFirefoxOptions( firefoxOptions )
7891
.setEdgeOptions( edgeOptions )

0 commit comments

Comments
 (0)