Skip to content

Commit bae493d

Browse files
committed
[java] Using json output for errors as well.
1 parent 43987a2 commit bae493d

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.common.collect.ImmutableList;
2020
import com.google.common.io.CharStreams;
21+
2122
import org.openqa.selenium.Beta;
2223
import org.openqa.selenium.Capabilities;
2324
import org.openqa.selenium.Platform;
@@ -100,23 +101,26 @@ private static String runCommand(String... command) {
100101
process.waitFor();
101102
code = process.exitValue();
102103
output = CharStreams.toString(new InputStreamReader(
103-
process.getInputStream(), StandardCharsets.UTF_8));
104+
process.getInputStream(), StandardCharsets.UTF_8));
104105
} catch (InterruptedException e) {
105106
LOG.warning(String.format("Interrupted exception running command %s: %s",
106-
Arrays.toString(command), e.getMessage()));
107+
Arrays.toString(command), e.getMessage()));
107108
Thread.currentThread().interrupt();
108109
} catch (Exception e) {
109110
LOG.warning(String.format("%s running command %s: %s",
110-
e.getClass().getSimpleName(), Arrays.toString(command), e.getMessage()));
111+
e.getClass().getSimpleName(), Arrays.toString(command),
112+
e.getMessage()));
111113
}
114+
SeleniumManagerJsonOutput jsonOutput = new Json()
115+
.toType(output, SeleniumManagerJsonOutput.class);
112116
if (code > 0) {
113-
throw new WebDriverException("Unsuccessful command executed: " + Arrays.toString(command) +
114-
"\n" + output);
117+
throw new WebDriverException(
118+
"Unsuccessful command executed: " + Arrays.toString(command) +
119+
"\n" + jsonOutput.result.message);
115120
}
116-
SeleniumManagerJsonOutput jsonOutput = new Json().toType(output,
117-
SeleniumManagerJsonOutput.class);
118-
jsonOutput.logs.stream().filter(log -> log.level.equalsIgnoreCase(WARN))
119-
.forEach(log -> LOG.warning(log.message));
121+
jsonOutput.logs.stream()
122+
.filter(log -> log.level.equalsIgnoreCase(WARN))
123+
.forEach(log -> LOG.warning(log.message));
120124
return jsonOutput.result.message;
121125
}
122126

@@ -172,15 +176,4 @@ public String getDriverPath(Capabilities options) {
172176
}
173177
return runCommand(commandList.toArray(new String[0]));
174178
}
175-
176-
public String getDriverPath(String driverName) {
177-
File binaryFile = getBinary();
178-
if(binaryFile == null) {
179-
return null;
180-
}
181-
ImmutableList<String> commandList = ImmutableList.of(binaryFile.getAbsolutePath(),
182-
"--driver", driverName,
183-
"--output", "json");
184-
return runCommand(commandList.toArray(new String[0]));
185-
}
186179
}

0 commit comments

Comments
 (0)