Skip to content

Commit cad08ad

Browse files
committed
[java] Process Selenium Manager output as JSON
1 parent 4f09bf0 commit cad08ad

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

java/src/org/openqa/selenium/manager/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ java_export(
1919
deps = [
2020
"//java/src/org/openqa/selenium:core",
2121
artifact("com.google.guava:guava"),
22+
artifact("com.google.code.gson:gson"),
2223
],
2324
)
2425

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import com.google.common.collect.ImmutableList;
2020
import com.google.common.io.CharStreams;
21+
import com.google.gson.Gson;
22+
import com.google.gson.GsonBuilder;
2123
import org.openqa.selenium.Beta;
2224
import org.openqa.selenium.Platform;
2325
import org.openqa.selenium.WebDriverException;
@@ -53,7 +55,7 @@ public class SeleniumManager {
5355

5456
private static final String SELENIUM_MANAGER = "selenium-manager";
5557
private static final String EXE = ".exe";
56-
private static final String INFO = "INFO\t";
58+
private static final String WARN = "WARN";
5759

5860
private static SeleniumManager manager;
5961

@@ -110,8 +112,12 @@ private static String runCommand(String... command) {
110112
throw new WebDriverException("Unsuccessful command executed: " + Arrays.toString(command) +
111113
"\n" + output);
112114
}
113-
114-
return output.replace(INFO, "").trim();
115+
Gson gson = new GsonBuilder().create();
116+
SeleniumManagerJsonOutput jsonOutput = gson.fromJson(output,
117+
SeleniumManagerJsonOutput.class);
118+
jsonOutput.logs.stream().filter(log -> log.level.equalsIgnoreCase(WARN))
119+
.forEach(log -> LOG.warning(log.message));
120+
return jsonOutput.result.message;
115121
}
116122

117123
/**
@@ -162,7 +168,7 @@ public String getDriverPath(String driverName) {
162168
File binaryFile = getBinary();
163169
if (binaryFile != null) {
164170
driverPath = runCommand(binaryFile.getAbsolutePath(),
165-
"--driver", driverName.replaceAll(EXE, ""));
171+
"--output", "json", "--driver", driverName.replaceAll(EXE, ""));
166172
}
167173
return driverPath;
168174
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.openqa.selenium.manager;
18+
19+
import java.util.List;
20+
21+
public class SeleniumManagerJsonOutput {
22+
23+
List<Log> logs;
24+
Result result;
25+
26+
class Log {
27+
String level;
28+
long timestamp;
29+
String message;
30+
}
31+
32+
class Result {
33+
int code;
34+
String message;
35+
}
36+
37+
}

0 commit comments

Comments
 (0)