Skip to content

Commit

Permalink
[java] Running IE-specific tests with bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Nov 28, 2018
1 parent 08f9334 commit 2fabca4
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 17 deletions.
9 changes: 9 additions & 0 deletions cpp/prebuilt/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
filegroup(
name = "prebuilt",
data = glob([
"**/*.*",
]),
visibility = [
"//java/client/test/org/openqa/selenium/testing/drivers:__pkg__",
],
)
44 changes: 28 additions & 16 deletions java/client/test/org/openqa/selenium/build/InProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,42 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class InProject {
/**
* Locates a file in the current project
*
* @param path path to file to locate from root of project
* @param paths path to file to locate from root of project
* @return file being sought, if it exists
* @throws org.openqa.selenium.WebDriverException wrapped FileNotFoundException if file could not
* be found
*/
public static Path locate(String path) {
Path actualPath = Paths.get(path);
if (Files.exists(actualPath)) {
return actualPath.toAbsolutePath();
}
public static Path locate(String... paths) {
Preconditions.checkArgument(paths.length > 0);
return Stream.of(paths)
.map(path -> Paths.get(path))
.filter(path -> Files.exists(path))
.findFirst()
.map(path -> path.toAbsolutePath())
.orElseGet(() -> {
Path root = findProjectRoot();
return Stream.of(paths)
.map(path -> {
Path needle = root.resolve(path);
return Files.exists(needle) ? needle : null;
})
.filter(Objects::nonNull)
.findFirst().orElseThrow(() -> new WebDriverException(new FileNotFoundException(
String.format("Could not find any of %s in the project",
Stream.of(paths).collect(Collectors.joining(","))))));
});
}

private static Path findProjectRoot() {
// Find the rakefile first
Path dir = Paths.get(".").toAbsolutePath();
Path pwd = dir;
Expand All @@ -51,15 +71,7 @@ public static Path locate(String path) {
}
dir = dir.getParent();
}
Preconditions.checkNotNull(dir, "Unable to find root of project in %s when looking for %s", pwd, path);
dir = dir.normalize();

Path needle = dir.resolve(path);
if (Files.exists(needle)) {
return needle;
}

throw new WebDriverException(new FileNotFoundException(
"Could not find " + path + " in the project"));
Preconditions.checkNotNull(dir, "Unable to find root of project in %s when looking", pwd);
return dir.normalize();
}
}
38 changes: 38 additions & 0 deletions java/client/test/org/openqa/selenium/ie/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
load("//java:bazel-rules.bzl", "gen_java_selenium_tests", "gen_java_tests")

SMALL_TESTS = [
"InternetExplorerOptionsTest.java",
]

gen_java_tests(
size = "small",
srcs = SMALL_TESTS,
deps = [
"//java/client/src/org/openqa/selenium/ie",
"//java/client/src/org/openqa/selenium/remote",
"//third_party/java/assertj",
"//third_party/java/guava",
"//third_party/java/junit",
"//third_party/java/mockito:mockito-core",
],
)

gen_java_selenium_tests(
drivers = ["ie"],
srcs = glob([
"*Test.java",
], exclude = SMALL_TESTS),
deps = [
"//java/client/src/org/openqa/selenium/ie",
"//java/client/src/org/openqa/selenium/remote",
"//java/client/test/org/openqa/selenium/build",
"//java/client/test/org/openqa/selenium",
"//java/client/test/org/openqa/selenium/environment",
"//java/client/test/org/openqa/selenium/testing",
"//java/client/test/org/openqa/selenium/testing/drivers",
"//third_party/java/assertj",
"//third_party/java/guava",
"//third_party/java/junit",
"//third_party/java/mockito:mockito-core",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ java_library(
"OutOfProcessSeleniumServer.java",
"WebDriverBuilder.java",
],
data = [
"//cpp/prebuilt",
],
deps = [
":browser",
"//java/client/src/org/openqa/selenium/chrome",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ private static InternetExplorerDriverService getService() {
InternetExplorerDriverService.Builder builder =
new InternetExplorerDriverService.Builder()
.usingDriverExecutable(
InProject.locate("build/cpp/Win32/Release/IEDriverServer.exe").toFile())
InProject.locate("build/cpp/Win32/Release/IEDriverServer.exe",
"cpp/prebuilt/Win32/Release/IEDriverServer.exe").toFile())
.usingAnyFreePort()
.withLogFile(new File("iedriver.log"))
.withLogLevel(InternetExplorerDriverLogLevel.valueOf(
Expand Down

0 comments on commit 2fabca4

Please sign in to comment.