Skip to content

Commit a701ea6

Browse files
committed
Ensure tests work with pinned browsers
This removes the requirement for the small and medium java tests to have firefox, chrome, or edge installed, provided the `--pin_browsers` flag is passed to bazel.
1 parent 6f0f3e9 commit a701ea6

File tree

7 files changed

+37
-16
lines changed

7 files changed

+37
-16
lines changed

java/client/test/org/openqa/selenium/environment/BUILD.bazel

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@rules_jvm_external//:defs.bzl", "artifact")
2+
load("//common/private:selenium_test.bzl", "BROWSERS")
23
load("//java:defs.bzl", "java_binary", "java_library", "java_test_suite")
34

45
filegroup(
@@ -98,13 +99,18 @@ java_library(
9899
],
99100
)
100101

102+
firefox = BROWSERS["firefox"]
103+
101104
java_test_suite(
102105
name = "MediumTests",
103106
size = "medium",
104107
srcs = glob(["**/*Test.java"]),
108+
data = firefox["data"],
109+
jvm_flags = firefox["jvm_flags"],
110+
tags = firefox["tags"],
105111
deps = [
106112
":environment",
107113
":test-base",
108114
artifact("junit:junit"),
109-
],
115+
] + firefox["deps"],
110116
)

java/client/test/org/openqa/selenium/firefox/FirefoxOptionsTest.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,16 @@ public void canConvertOptionsWithPrefsToCapabilitiesAndRestoreBack() {
305305
}
306306

307307
@Test
308-
public void canConvertOptionsWithBinaryToCapabilitiesAndRestoreBack() {
308+
public void canConvertOptionsWithBinaryToCapabilitiesAndRestoreBack() throws IOException {
309+
// Don't assume Firefox is actually installed and available
310+
Path tempFile = Files.createTempFile("firefoxoptions", "test");
311+
309312
FirefoxOptions options = new FirefoxOptions(
310-
new MutableCapabilities(new FirefoxOptions().setBinary(new FirefoxBinary())));
313+
new MutableCapabilities(new FirefoxOptions().setBinary(new FirefoxBinary(tempFile.toFile()))));
311314
Object options2 = options.asMap().get(FirefoxOptions.FIREFOX_OPTIONS);
312315
assertThat(options2)
313316
.asInstanceOf(InstanceOfAssertFactories.MAP)
314-
.containsEntry("binary", new FirefoxBinary().getPath().replaceAll("\\\\", "/"));
317+
.containsEntry("binary", new FirefoxBinary(tempFile.toFile()).getPath().replaceAll("\\\\", "/"));
315318
}
316319

317320
@Test

java/client/test/org/openqa/selenium/ie/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ java_test_suite(
1212
["*.java"],
1313
exclude = LARGE_TESTS,
1414
),
15+
tags = [
16+
"requires-network",
17+
],
1518
deps = [
1619
"//java/client/src/org/openqa/selenium/ie",
1720
"//java/client/src/org/openqa/selenium/json",

java/server/test/com/thoughtworks/selenium/webdriven/BUILD.bazel

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
load("@rules_jvm_external//:defs.bzl", "artifact")
2+
load("//common/private:selenium_test.bzl", "BROWSERS")
23
load("//java:defs.bzl", "java_test_suite")
34

5+
firefox = BROWSERS["firefox"]
6+
47
java_test_suite(
58
name = "MediumTests",
69
size = "medium",
710
srcs = glob(["*Test.java"]),
11+
data = firefox["data"],
812
javacopts = [
913
"-source",
1014
"11",
1115
"-target",
1216
"11",
1317
],
18+
jvm_flags = firefox["jvm_flags"],
19+
tags = firefox["tags"],
1420
deps = [
1521
"//java/client/src/com/thoughtworks/selenium",
1622
"//java/client/src/org/openqa/selenium/remote",
@@ -23,5 +29,5 @@ java_test_suite(
2329
"//java/server/src/org/openqa/selenium/remote/server",
2430
artifact("io.opentelemetry:opentelemetry-api"),
2531
artifact("junit:junit"),
26-
],
32+
] + firefox["deps"],
2733
)

java/server/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.openqa.selenium.grid.node.config;
1919

20+
import com.google.common.collect.ImmutableMap;
2021
import org.assertj.core.api.Condition;
2122
import org.junit.Test;
2223
import org.openqa.selenium.Capabilities;
@@ -50,8 +51,6 @@
5051
import static org.junit.Assume.assumeFalse;
5152
import static org.junit.Assume.assumeTrue;
5253

53-
import com.google.common.collect.ImmutableMap;
54-
5554
@SuppressWarnings("DuplicatedCode")
5655
public class NodeOptionsTest {
5756

@@ -115,11 +114,9 @@ public void shouldDetectCorrectDriversOnMac() {
115114
return Collections.emptySet();
116115
});
117116

118-
assertThat(reported).is(supporting("chrome"));
119-
assertThat(reported).is(supporting("firefox"));
120-
assertThat(reported).isNot(supporting("internet explorer"));
121-
assertThat(reported).is(supporting("MicrosoftEdge"));
117+
// There may be more drivers available, but we know that these are meant to be here.
122118
assertThat(reported).is(supporting("safari"));
119+
assertThat(reported).isNot(supporting("internet explorer"));
123120
}
124121

125122
@Test
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
load("@rules_jvm_external//:defs.bzl", "artifact")
2+
load("//common/private:selenium_test.bzl", "BROWSERS")
23
load("//java:defs.bzl", "java_test_suite")
34

5+
firefox = BROWSERS["firefox"]
6+
47
java_test_suite(
58
name = "MediumTests",
69
size = "medium",
710
srcs = glob(["*.java"]),
8-
jvm_flags = [
11+
data = firefox["data"],
12+
jvm_flags = firefox["jvm_flags"] + [
913
"-Dselenium.browser=*firefox",
1014
],
1115
tags = [
1216
"no-sandbox",
1317
],
1418
deps = [
19+
"//java/client/src/org/openqa/selenium/chrome",
1520
"//java/client/src/org/openqa/selenium/remote",
1621
"//java/client/test/org/openqa/selenium/environment",
1722
"//java/server/src/org/openqa/selenium/server/htmlrunner",
1823
artifact("com.google.guava:guava"),
1924
artifact("junit:junit"),
20-
],
25+
] + firefox["deps"],
2126
)

java/server/test/org/openqa/selenium/server/htmlrunner/CoreSelfTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
import org.junit.After;
2222
import org.junit.Before;
2323
import org.junit.Test;
24+
import org.openqa.selenium.chrome.ChromeDriverInfo;
2425
import org.openqa.selenium.environment.webserver.AppServer;
2526
import org.openqa.selenium.environment.webserver.NettyAppServer;
26-
import org.openqa.selenium.os.ExecutableFinder;
27+
import org.openqa.selenium.firefox.GeckoDriverInfo;
2728

2829
import java.io.IOException;
2930
import java.nio.file.Files;
@@ -46,11 +47,11 @@ public void detectBrowser() {
4647

4748
switch (browser) {
4849
case "*firefox":
49-
assumeNotNull(new ExecutableFinder().find("geckodriver"));
50+
assumeNotNull(new GeckoDriverInfo().isAvailable());
5051
break;
5152

5253
case "*googlechrome":
53-
assumeNotNull(new ExecutableFinder().find("chromedriver"));
54+
assumeNotNull(new ChromeDriverInfo().isAvailable());
5455
break;
5556

5657
default:

0 commit comments

Comments
 (0)