Skip to content

Commit

Permalink
[java] Process Selenium Manager output as JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia authored and diemol committed Feb 17, 2023
1 parent 8b4b818 commit 0b59c47
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/manager/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ java_export(
deps = [
"//java/src/org/openqa/selenium:core",
artifact("com.google.guava:guava"),
artifact("com.google.code.gson:gson"),
],
)

Expand Down
12 changes: 8 additions & 4 deletions java/src/org/openqa/selenium/manager/SeleniumManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.common.collect.ImmutableList;
import com.google.common.io.CharStreams;
import com.google.gson.GsonBuilder;
import org.openqa.selenium.Beta;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriverException;
Expand Down Expand Up @@ -53,7 +54,7 @@ public class SeleniumManager {

private static final String SELENIUM_MANAGER = "selenium-manager";
private static final String EXE = ".exe";
private static final String INFO = "INFO\t";
private static final String WARN = "WARN";

private static SeleniumManager manager;

Expand Down Expand Up @@ -110,8 +111,11 @@ private static String runCommand(String... command) {
throw new WebDriverException("Unsuccessful command executed: " + Arrays.toString(command) +
"\n" + output);
}

return output.replace(INFO, "").trim();
SeleniumManagerJsonOutput jsonOutput = new GsonBuilder().create().fromJson(output,
SeleniumManagerJsonOutput.class);
jsonOutput.logs.stream().filter(log -> log.level.equalsIgnoreCase(WARN))
.forEach(log -> LOG.warning(log.message));
return jsonOutput.result.message;
}

/**
Expand Down Expand Up @@ -162,7 +166,7 @@ public String getDriverPath(String driverName) {
File binaryFile = getBinary();
if (binaryFile != null) {
driverPath = runCommand(binaryFile.getAbsolutePath(),
"--driver", driverName.replaceAll(EXE, ""));
"--output", "json", "--driver", driverName.replaceAll(EXE, ""));
}
return driverPath;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.openqa.selenium.manager;

import java.util.List;

public class SeleniumManagerJsonOutput {

List<Log> logs;
Result result;

class Log {
String level;
long timestamp;
String message;
}

class Result {
int code;
String message;
}

}

0 comments on commit 0b59c47

Please sign in to comment.