Skip to content

Commit 8921182

Browse files
authored
[java] add more logging to Selenium Manager (#11959)
* [java] add more logging to Selenium Manager * Addressing PR comments --------- Co-authored-by: Diego Molina <[email protected]> Co-authored-by: Diego Molina <[email protected]> Fixes #11642
1 parent 2266ffc commit 8921182

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

java/src/org/openqa/selenium/manager/SeleniumManager.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.Arrays;
3636
import java.util.List;
3737
import java.util.Map;
38+
import java.util.logging.Level;
3839
import java.util.logging.Logger;
3940

4041
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
@@ -59,6 +60,7 @@ public class SeleniumManager {
5960
private static final String SELENIUM_MANAGER = "selenium-manager";
6061
private static final String EXE = ".exe";
6162
private static final String WARN = "WARN";
63+
private static final String DEBUG = "DEBUG";
6264

6365
private static SeleniumManager manager;
6466

@@ -94,6 +96,7 @@ public static SeleniumManager getInstance() {
9496
* @return the standard output of the execution.
9597
*/
9698
private static String runCommand(String... command) {
99+
LOG.fine(String.format("Executing Process: %s", command));
97100
String output = "";
98101
int code = 0;
99102
try {
@@ -120,8 +123,14 @@ private static String runCommand(String... command) {
120123
"\n" + jsonOutput.result.message);
121124
}
122125
jsonOutput.logs.stream()
123-
.filter(log -> log.level.equalsIgnoreCase(WARN))
124-
.forEach(log -> LOG.warning(log.message));
126+
.forEach(logged -> {
127+
if(logged.level.equalsIgnoreCase(WARN)) {
128+
LOG.warning(logged.message);
129+
}
130+
if(logged.level.equalsIgnoreCase(DEBUG)) {
131+
LOG.fine(logged.message);
132+
}
133+
});
125134
return jsonOutput.result.message;
126135
}
127136

@@ -187,24 +196,34 @@ private String getBrowserBinary(Capabilities options) {
187196
* @return the location of the driver.
188197
*/
189198
public String getDriverPath(Capabilities options) {
190-
File binaryFile = getBinary();
199+
LOG.info("applicable driver not found; attempting to install with Selenium Manager (Beta)");
200+
File binaryFile = getBinary();
191201
if (binaryFile == null) {
192202
return null;
193203
}
194-
List<String> commandList = new ArrayList<>(
195-
Arrays.asList(binaryFile.getAbsolutePath(),
196-
"--browser",
197-
options.getBrowserName(),
198-
"--output", "json"));
204+
List<String> commandList = new ArrayList<>();
205+
commandList.add(binaryFile.getAbsolutePath());
206+
commandList.add("--browser");
207+
commandList.add(options.getBrowserName());
208+
commandList.add("--output");
209+
commandList.add("json");
199210
if (!options.getBrowserVersion().isEmpty()) {
200-
commandList.addAll(Arrays.asList("--browser-version", options.getBrowserVersion()));
211+
commandList.add("--browser-version");
212+
commandList.add(options.getBrowserVersion());
201213
}
202214

203215
String browserBinary = getBrowserBinary(options);
204216
if (browserBinary != null && !browserBinary.isEmpty()) {
205-
commandList.addAll(Arrays.asList("--browser-path", browserBinary));
217+
commandList.add("--browser-path");
218+
commandList.add(browserBinary);
219+
}
220+
221+
if (LOG.getLevel().intValue() > Level.FINE.intValue()) {
222+
commandList.add("--verbose");
206223
}
207224

208-
return runCommand(commandList.toArray(new String[0]));
225+
String path = runCommand(commandList.toArray(new String[0]));
226+
LOG.fine(String.format("Using driver at location: %s", path));
227+
return path;
209228
}
210229
}

0 commit comments

Comments
 (0)