Skip to content

Commit

Permalink
[java] toggle selenium manager output by exit value instead of content
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Nov 29, 2022
1 parent 18fc634 commit 37498f8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions java/src/org/openqa/selenium/manager/SeleniumManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ public static SeleniumManager getInstance() {
*/
private static String runCommand(String... command) {
String output = "";
int code = 0;
try {
Process process = new ProcessBuilder(command)
.redirectErrorStream(true).start();
process.waitFor();
code = process.exitValue();
output = CharStreams.toString(new InputStreamReader(
process.getInputStream(), StandardCharsets.UTF_8));
} catch (InterruptedException e) {
Expand All @@ -103,12 +105,12 @@ private static String runCommand(String... command) {
LOG.warning(String.format("%s running command %s: %s",
e.getClass().getSimpleName(), Arrays.toString(command), e.getMessage()));
}
if (!output.startsWith(INFO)) {
throw new WebDriverException("Error running selenium-manager: " + Arrays.toString(command) +
": " + output);
if (code > 0) {
throw new WebDriverException("Unsuccessful command executed: " + Arrays.toString(command) +
"\n" + output);
}

return output.trim();
return output.replace(INFO, "").trim();
}

/**
Expand Down Expand Up @@ -156,9 +158,8 @@ public String getDriverPath(String driverName) {
String driverPath = null;
File binaryFile = getBinary();
if (binaryFile != null) {
String output = runCommand(binaryFile.getAbsolutePath(),
driverPath = runCommand(binaryFile.getAbsolutePath(),
"--driver", driverName.replaceAll(EXE, ""));
driverPath = output.replace(INFO, "");
}
return driverPath;
}
Expand Down

0 comments on commit 37498f8

Please sign in to comment.