Skip to content

Commit 0b59c47

Browse files
bonigarciadiemol
authored andcommitted
[java] Process Selenium Manager output as JSON
1 parent 8b4b818 commit 0b59c47

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-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: 8 additions & 4 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+
import com.google.gson.GsonBuilder;
2122
import org.openqa.selenium.Beta;
2223
import org.openqa.selenium.Platform;
2324
import org.openqa.selenium.WebDriverException;
@@ -53,7 +54,7 @@ public class SeleniumManager {
5354

5455
private static final String SELENIUM_MANAGER = "selenium-manager";
5556
private static final String EXE = ".exe";
56-
private static final String INFO = "INFO\t";
57+
private static final String WARN = "WARN";
5758

5859
private static SeleniumManager manager;
5960

@@ -110,8 +111,11 @@ private static String runCommand(String... command) {
110111
throw new WebDriverException("Unsuccessful command executed: " + Arrays.toString(command) +
111112
"\n" + output);
112113
}
113-
114-
return output.replace(INFO, "").trim();
114+
SeleniumManagerJsonOutput jsonOutput = new GsonBuilder().create().fromJson(output,
115+
SeleniumManagerJsonOutput.class);
116+
jsonOutput.logs.stream().filter(log -> log.level.equalsIgnoreCase(WARN))
117+
.forEach(log -> LOG.warning(log.message));
118+
return jsonOutput.result.message;
115119
}
116120

117121
/**
@@ -162,7 +166,7 @@ public String getDriverPath(String driverName) {
162166
File binaryFile = getBinary();
163167
if (binaryFile != null) {
164168
driverPath = runCommand(binaryFile.getAbsolutePath(),
165-
"--driver", driverName.replaceAll(EXE, ""));
169+
"--output", "json", "--driver", driverName.replaceAll(EXE, ""));
166170
}
167171
return driverPath;
168172
}
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)