|
25 | 25 | import java.nio.file.FileVisitResult;
|
26 | 26 | import java.nio.file.Files;
|
27 | 27 | import java.nio.file.Path;
|
| 28 | +import java.nio.file.Paths; |
28 | 29 | import java.nio.file.SimpleFileVisitor;
|
29 | 30 | import java.nio.file.attribute.BasicFileAttributes;
|
30 | 31 | import java.util.ArrayList;
|
@@ -61,11 +62,11 @@ public class SeleniumManager {
|
61 | 62 | private static final Logger LOG = Logger.getLogger(SeleniumManager.class.getName());
|
62 | 63 |
|
63 | 64 | private static final String SELENIUM_MANAGER = "selenium-manager";
|
64 |
| - private static final String EXE = ".exe"; |
65 | 65 |
|
66 | 66 | private static volatile SeleniumManager manager;
|
67 | 67 |
|
68 |
| - private Path binary; |
| 68 | + private final String managerPath = System.getenv("SE_MANAGER_PATH"); |
| 69 | + private Path binary = managerPath == null ? null : Paths.get(managerPath); |
69 | 70 |
|
70 | 71 | /** Wrapper for the Selenium Manager binary. */
|
71 | 72 | private SeleniumManager() {
|
@@ -158,30 +159,31 @@ private static Result runCommand(Path binary, List<String> arguments) {
|
158 | 159 | */
|
159 | 160 | private synchronized Path getBinary() {
|
160 | 161 | if (binary == null) {
|
161 |
| - try { |
162 |
| - Platform current = Platform.getCurrent(); |
163 |
| - String folder = "linux"; |
164 |
| - String extension = ""; |
165 |
| - if (current.is(WINDOWS)) { |
166 |
| - extension = EXE; |
167 |
| - folder = "windows"; |
168 |
| - } else if (current.is(MAC)) { |
169 |
| - folder = "macos"; |
170 |
| - } |
171 |
| - String binaryPath = String.format("%s/%s%s", folder, SELENIUM_MANAGER, extension); |
172 |
| - try (InputStream inputStream = this.getClass().getResourceAsStream(binaryPath)) { |
173 |
| - Path tmpPath = Files.createTempDirectory(SELENIUM_MANAGER + System.nanoTime()); |
| 162 | + Platform current = Platform.getCurrent(); |
| 163 | + String folder = "linux"; |
| 164 | + String extension = ""; |
| 165 | + if (current.is(WINDOWS)) { |
| 166 | + extension = ".exe"; |
| 167 | + folder = "windows"; |
| 168 | + } else if (current.is(MAC)) { |
| 169 | + folder = "macos"; |
| 170 | + } |
| 171 | + String binaryPath = String.format("%s/%s%s", folder, SELENIUM_MANAGER, extension); |
| 172 | + try (InputStream inputStream = this.getClass().getResourceAsStream(binaryPath)) { |
| 173 | + Path tmpPath = Files.createTempDirectory(SELENIUM_MANAGER + System.nanoTime()); |
174 | 174 |
|
175 |
| - deleteOnExit(tmpPath); |
| 175 | + deleteOnExit(tmpPath); |
176 | 176 |
|
177 |
| - binary = tmpPath.resolve(SELENIUM_MANAGER + extension); |
178 |
| - Files.copy(inputStream, binary, REPLACE_EXISTING); |
179 |
| - } |
180 |
| - binary.toFile().setExecutable(true); |
| 177 | + binary = tmpPath.resolve(SELENIUM_MANAGER + extension); |
| 178 | + Files.copy(inputStream, binary, REPLACE_EXISTING); |
181 | 179 | } catch (Exception e) {
|
182 | 180 | throw new WebDriverException("Unable to obtain Selenium Manager Binary", e);
|
183 | 181 | }
|
| 182 | + } else if (!Files.exists(binary)) { |
| 183 | + throw new WebDriverException(String.format("Unable to obtain Selenium Manager Binary at: %s", binary)); |
184 | 184 | }
|
| 185 | + binary.toFile().setExecutable(true); |
| 186 | + |
185 | 187 | LOG.fine(String.format("Selenium Manager binary found at: %s", binary));
|
186 | 188 |
|
187 | 189 | return binary;
|
|
0 commit comments