19
19
import static org .openqa .selenium .Platform .MAC ;
20
20
import static org .openqa .selenium .Platform .WINDOWS ;
21
21
22
+ import java .io .IOException ;
22
23
import java .io .InputStream ;
23
24
import java .nio .file .Files ;
24
25
import java .nio .file .Path ;
29
30
import java .util .Map ;
30
31
import java .util .logging .Level ;
31
32
import java .util .logging .Logger ;
32
-
33
33
import org .openqa .selenium .Beta ;
34
34
import org .openqa .selenium .BuildInfo ;
35
35
import org .openqa .selenium .Capabilities ;
@@ -58,18 +58,13 @@ public class SeleniumManager {
58
58
59
59
private static final Logger LOG = Logger .getLogger (SeleniumManager .class .getName ());
60
60
61
-
62
61
private static final String SELENIUM_MANAGER = "selenium-manager" ;
63
62
private static final String DEFAULT_CACHE_PATH = "~/.cache/selenium" ;
64
63
private static final String BINARY_PATH_FORMAT = "/manager/%s/%s" ;
65
64
private static final String HOME = "~" ;
66
65
private static final String CACHE_PATH_ENV = "SE_CACHE_PATH" ;
67
66
private static final String BETA_PREFIX = "0." ;
68
-
69
67
private static final String EXE = ".exe" ;
70
- private static final String INFO = "INFO" ;
71
- private static final String WARN = "WARN" ;
72
- private static final String DEBUG = "DEBUG" ;
73
68
74
69
private static volatile SeleniumManager manager ;
75
70
private final String managerPath = System .getenv ("SE_MANAGER_PATH" );
@@ -290,7 +285,7 @@ private Level getLogLevel() {
290
285
return level ;
291
286
}
292
287
293
- private Path getBinaryInCache (String binaryName ) {
288
+ private Path getBinaryInCache (String binaryName ) throws IOException {
294
289
String cachePath = DEFAULT_CACHE_PATH .replace (HOME , System .getProperty ("user.home" ));
295
290
296
291
// Look for cache path as env
@@ -299,6 +294,14 @@ private Path getBinaryInCache(String binaryName) {
299
294
cachePath = cachePathEnv ;
300
295
}
301
296
302
- return Paths .get (cachePath + String .format (BINARY_PATH_FORMAT , seleniumManagerVersion , binaryName ));
297
+ // If cache path is not writable, SM will be extracted to a temporal folder
298
+ Path cacheParent = Paths .get (cachePath );
299
+ if (!Files .isWritable (cacheParent )) {
300
+ cacheParent = Files .createTempDirectory (SELENIUM_MANAGER );
301
+ }
302
+
303
+ return Paths .get (
304
+ cacheParent .toString (),
305
+ String .format (BINARY_PATH_FORMAT , seleniumManagerVersion , binaryName ));
303
306
}
304
307
}
0 commit comments