Skip to content

Commit

Permalink
[java] add more logging to Selenium Manager (#11959)
Browse files Browse the repository at this point in the history
* [java] add more logging to Selenium Manager

* Addressing PR comments

---------

Co-authored-by: Diego Molina <diemol@gmail.com>
Co-authored-by: Diego Molina <diemol@users.noreply.github.com>

Fixes #11642
  • Loading branch information
titusfortner authored May 2, 2023
1 parent 2266ffc commit 8921182
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions java/src/org/openqa/selenium/manager/SeleniumManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

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

private static SeleniumManager manager;

Expand Down Expand Up @@ -94,6 +96,7 @@ public static SeleniumManager getInstance() {
* @return the standard output of the execution.
*/
private static String runCommand(String... command) {
LOG.fine(String.format("Executing Process: %s", command));
String output = "";
int code = 0;
try {
Expand All @@ -120,8 +123,14 @@ private static String runCommand(String... command) {
"\n" + jsonOutput.result.message);
}
jsonOutput.logs.stream()
.filter(log -> log.level.equalsIgnoreCase(WARN))
.forEach(log -> LOG.warning(log.message));
.forEach(logged -> {
if(logged.level.equalsIgnoreCase(WARN)) {
LOG.warning(logged.message);
}
if(logged.level.equalsIgnoreCase(DEBUG)) {
LOG.fine(logged.message);
}
});
return jsonOutput.result.message;
}

Expand Down Expand Up @@ -187,24 +196,34 @@ private String getBrowserBinary(Capabilities options) {
* @return the location of the driver.
*/
public String getDriverPath(Capabilities options) {
File binaryFile = getBinary();
LOG.info("applicable driver not found; attempting to install with Selenium Manager (Beta)");
File binaryFile = getBinary();
if (binaryFile == null) {
return null;
}
List<String> commandList = new ArrayList<>(
Arrays.asList(binaryFile.getAbsolutePath(),
"--browser",
options.getBrowserName(),
"--output", "json"));
List<String> commandList = new ArrayList<>();
commandList.add(binaryFile.getAbsolutePath());
commandList.add("--browser");
commandList.add(options.getBrowserName());
commandList.add("--output");
commandList.add("json");
if (!options.getBrowserVersion().isEmpty()) {
commandList.addAll(Arrays.asList("--browser-version", options.getBrowserVersion()));
commandList.add("--browser-version");
commandList.add(options.getBrowserVersion());
}

String browserBinary = getBrowserBinary(options);
if (browserBinary != null && !browserBinary.isEmpty()) {
commandList.addAll(Arrays.asList("--browser-path", browserBinary));
commandList.add("--browser-path");
commandList.add(browserBinary);
}

if (LOG.getLevel().intValue() > Level.FINE.intValue()) {
commandList.add("--verbose");
}

return runCommand(commandList.toArray(new String[0]));
String path = runCommand(commandList.toArray(new String[0]));
LOG.fine(String.format("Using driver at location: %s", path));
return path;
}
}

0 comments on commit 8921182

Please sign in to comment.