Skip to content

Commit 1de6a52

Browse files
bonigarciadiemol
andauthored
[java] Process Selenium Manager output as JSON (#11663)
* [java] Process Selenium Manager output as JSON * [java] Use internal JSON parser instead of GSON --------- Co-authored-by: Diego Molina <[email protected]>
1 parent 841eb80 commit 1de6a52

File tree

3 files changed

+101
-4
lines changed

3 files changed

+101
-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
@@ -18,6 +18,7 @@ java_export(
1818
],
1919
deps = [
2020
"//java/src/org/openqa/selenium:core",
21+
"//java/src/org/openqa/selenium/json",
2122
artifact("com.google.guava:guava"),
2223
],
2324
)

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.openqa.selenium.Capabilities;
2323
import org.openqa.selenium.Platform;
2424
import org.openqa.selenium.WebDriverException;
25+
import org.openqa.selenium.json.Json;
2526

2627
import java.io.File;
2728
import java.io.IOException;
@@ -55,7 +56,7 @@ public class SeleniumManager {
5556

5657
private static final String SELENIUM_MANAGER = "selenium-manager";
5758
private static final String EXE = ".exe";
58-
private static final String INFO = "INFO\t";
59+
private static final String WARN = "WARN";
5960

6061
private static SeleniumManager manager;
6162

@@ -112,9 +113,11 @@ private static String runCommand(String... command) {
112113
throw new WebDriverException("Unsuccessful command executed: " + Arrays.toString(command) +
113114
"\n" + output);
114115
}
115-
116-
String[] lines = output.split("\n");
117-
return lines[lines.length -1].replace(INFO, "").trim();
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));
120+
return jsonOutput.result.message;
118121
}
119122

120123
/**
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
public List<Log> logs;
24+
public Result result;
25+
26+
public List<Log> getLogs() {
27+
return logs;
28+
}
29+
30+
public void setLogs(List<Log> logs) {
31+
this.logs = logs;
32+
}
33+
34+
public Result getResult() {
35+
return result;
36+
}
37+
38+
public void setResult(Result result) {
39+
this.result = result;
40+
}
41+
42+
public static class Log {
43+
public String level;
44+
long timestamp;
45+
public String message;
46+
47+
public String getLevel() {
48+
return level;
49+
}
50+
51+
public void setLevel(String level) {
52+
this.level = level;
53+
}
54+
55+
public long getTimestamp() {
56+
return timestamp;
57+
}
58+
59+
public void setTimestamp(long timestamp) {
60+
this.timestamp = timestamp;
61+
}
62+
63+
public String getMessage() {
64+
return message;
65+
}
66+
67+
public void setMessage(String message) {
68+
this.message = message;
69+
}
70+
}
71+
72+
public static class Result {
73+
public int code;
74+
public String message;
75+
76+
public int getCode() {
77+
return code;
78+
}
79+
80+
public void setCode(int code) {
81+
this.code = code;
82+
}
83+
84+
public String getMessage() {
85+
return message;
86+
}
87+
88+
public void setMessage(String message) {
89+
this.message = message;
90+
}
91+
}
92+
93+
}

0 commit comments

Comments
 (0)