Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 44 additions & 26 deletions java/src/org/openqa/selenium/manager/SeleniumManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonException;

/**
* This implementation is still in beta, and may change.
Expand Down Expand Up @@ -101,8 +102,8 @@ public static SeleniumManager getInstance() {
*/
private static String runCommand(String... command) {
LOG.fine(String.format("Executing Process: %s", Arrays.toString(command)));
String output = "";
int code = 0;
String output;
int code;
try {
Process process = new ProcessBuilder(command).redirectErrorStream(true).start();
process.waitFor();
Expand All @@ -111,35 +112,52 @@ private static String runCommand(String... command) {
CharStreams.toString(
new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8));
} catch (InterruptedException e) {
LOG.warning(
String.format(
"Interrupted exception running command %s: %s",
Arrays.toString(command), e.getMessage()));
Thread.currentThread().interrupt();
throw new WebDriverException(
"Interrupted while running command: "
+ Arrays.toString(command),
e);
} catch (Exception e) {
LOG.warning(
String.format(
"%s running command %s: %s",
e.getClass().getSimpleName(), Arrays.toString(command), e.getMessage()));
throw new WebDriverException(
"Failed to run command: "
+ Arrays.toString(command),
e);
}
SeleniumManagerJsonOutput jsonOutput = null;
JsonException failedToParse = null;
String dump = output;
if (!output.isEmpty()) {
try {
jsonOutput = new Json().toType(output, SeleniumManagerJsonOutput.class);
jsonOutput.logs.forEach(
logged -> {
if (logged.level.equalsIgnoreCase(WARN)) {
LOG.warning(logged.message);
}
if (logged.level.equalsIgnoreCase(DEBUG) || logged.level.equalsIgnoreCase(INFO)) {
LOG.fine(logged.message);
}
});
dump = jsonOutput.result.message;
} catch (JsonException e) {
failedToParse = e;
}
}
SeleniumManagerJsonOutput jsonOutput =
new Json().toType(output, SeleniumManagerJsonOutput.class);
if (code > 0) {
if (code != 0) {
throw new WebDriverException(
"Command failed with code: "
+ code
+ ", executed: "
+ Arrays.toString(command)
+ "\n"
+ dump, failedToParse);
} else if (failedToParse != null) {
throw new WebDriverException(
"Unsuccessful command executed: "
+ Arrays.toString(command)
+ "\n"
+ jsonOutput.result.message);
"Failed to parse json output, executed: "
+ Arrays.toString(command)
+ "\n"
+ dump, failedToParse);
}
jsonOutput.logs.forEach(
logged -> {
if (logged.level.equalsIgnoreCase(WARN)) {
LOG.warning(logged.message);
}
if (logged.level.equalsIgnoreCase(DEBUG) || logged.level.equalsIgnoreCase(INFO)) {
LOG.fine(logged.message);
}
});
return jsonOutput.result.message;
}

Expand Down