Skip to content

Commit c4730d3

Browse files
Merge branch 'SeleniumHQ:trunk' into patch-4
2 parents 6ac5b58 + c10bff7 commit c4730d3

12 files changed

Lines changed: 98 additions & 71 deletions

File tree

.github/workflows/java.yml

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@ jobs:
9898
with:
9999
query: attr(tags, lint, tests(//java/...))
100100

101-
chrome_tests:
101+
browser_tests:
102102
needs: small_tests
103103
runs-on: ubuntu-latest
104+
strategy:
105+
matrix:
106+
browser: [ chrome, firefox ]
104107
steps:
105108
- name: Checkout source tree
106109
uses: actions/checkout@v2
@@ -110,42 +113,9 @@ jobs:
110113
path: |
111114
~/.cache/bazel-disk
112115
~/.cache/bazel-repo
113-
key: ${{ runner.os }}-bazel-chrome-tests-${{ hashFiles('**/BUILD.bazel') }}
116+
key: ${{ runner.os }}-bazel-${{ matrix.browser }}-tests-${{ hashFiles('**/BUILD.bazel') }}
114117
restore-keys: |
115-
${{ runner.os }}-bazel-chrome-tests-
116-
${{ runner.os }}-bazel-build-
117-
- name: Setup bazelisk
118-
uses: ./.github/actions/setup-bazelisk
119-
- name: Setup Java
120-
uses: actions/setup-java@v1
121-
with:
122-
java-version: '11'
123-
- name: Setup Chrome and ChromeDriver
124-
uses: ./.github/actions/setup-chrome
125-
- name: Start XVFB
126-
run: Xvfb :99 &
127-
- name: Run browser tests in Chrome
128-
uses: ./.github/actions/bazel-test
129-
with:
130-
query: attr(tags, chrome, tests(//java/...)) except attr(tags, remote, tests(//java/...))
131-
env:
132-
DISPLAY: :99
133-
134-
firefox_tests:
135-
needs: small_tests
136-
runs-on: ubuntu-latest
137-
steps:
138-
- name: Checkout source tree
139-
uses: actions/checkout@v2
140-
- name: Cache Bazel artifacts
141-
uses: actions/cache@v2
142-
with:
143-
path: |
144-
~/.cache/bazel-disk
145-
~/.cache/bazel-repo
146-
key: ${{ runner.os }}-bazel-firefox-tests-${{ hashFiles('**/BUILD.bazel') }}
147-
restore-keys: |
148-
${{ runner.os }}-bazel-firefox-tests-
118+
${{ runner.os }}-bazel-${{ matrix.browser }}-tests-
149119
${{ runner.os }}-bazel-build-
150120
- name: Setup bazelisk
151121
uses: ./.github/actions/setup-bazelisk
@@ -155,20 +125,24 @@ jobs:
155125
java-version: '11'
156126
- name: Setup Firefox and GeckoDriver
157127
uses: ./.github/actions/setup-firefox
128+
- name: Setup Chrome and ChromeDriver
129+
uses: ./.github/actions/setup-chrome
158130
- name: Start XVFB
159131
run: Xvfb :99 &
160-
- name: Run browser tests in Firefox
132+
- name: Run browser tests in ${{ matrix.browser }}
161133
uses: ./.github/actions/bazel-test
162134
with:
163-
query: attr(tags, firefox, tests(//java/...)) except attr(tags, 'rc|remote', tests(//java/...))
135+
query: attr(tags, ${{ matrix.browser }}, tests(//java/...)) except attr(tags, 'lint|rc|remote', tests(//java/...))
164136
env:
165137
DISPLAY: :99
166138

167-
168139
server_tests:
169140
if: ${{ always() }}
170-
needs: [ chrome_tests, firefox_tests ]
141+
needs: [ browser_tests ]
171142
runs-on: ubuntu-latest
143+
strategy:
144+
matrix:
145+
browser: [ chrome, firefox ]
172146
steps:
173147
- name: Checkout source tree
174148
uses: actions/checkout@v2
@@ -178,28 +152,27 @@ jobs:
178152
path: |
179153
~/.cache/bazel-disk
180154
~/.cache/bazel-repo
181-
key: ${{ runner.os }}-bazel-server-tests-${{ hashFiles('**/BUILD.bazel') }}
155+
key: ${{ runner.os }}-bazel-${{ matrix.browser }}-server-tests-${{ hashFiles('**/BUILD.bazel') }}
182156
restore-keys: |
183-
${{ runner.os }}-bazel-server-tests-
184-
${{ runner.os }}-bazel-chrome-tests-
185-
${{ runner.os }}-bazel-firefox-tests-
157+
${{ runner.os }}-bazel-${{ matrix.browser }}-server-tests-
158+
${{ runner.os }}-bazel-${{ matrix.browser }}-tests-
186159
${{ runner.os }}-bazel-build-
187160
- name: Setup bazelisk
188161
uses: ./.github/actions/setup-bazelisk
189162
- name: Setup Java
190163
uses: actions/setup-java@v1
191164
with:
192165
java-version: '11'
193-
- name: Setup Chrome and ChromeDriver
194-
uses: ./.github/actions/setup-chrome
195166
- name: Setup Firefox and GeckoDriver
196167
uses: ./.github/actions/setup-firefox
168+
- name: Setup Chrome and ChromeDriver
169+
uses: ./.github/actions/setup-chrome
197170
- name: Start XVFB
198171
run: Xvfb :99 &
199172
- name: Run server tests
200173
uses: ./.github/actions/bazel-test
201174
with:
202-
query: tests(//java/...) except attr(tags, 'rc|lint|ie|edge|edgehtml|safari', tests(//java/...))
175+
query: attr(tags, ${{ matrix.browser }}, tests(//java/...)) intersect attr(tags, 'remote', tests(//java/...))
203176
env:
204177
DISPLAY: :99
205178

WORKSPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ selenium_register_dotnet()
123123

124124
http_archive(
125125
name = "build_bazel_rules_nodejs",
126-
sha256 = "cfc289523cf1594598215901154a6c2515e8bf3671fd708264a6f6aefe02bf39",
127-
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/4.4.6/rules_nodejs-4.4.6.tar.gz"],
126+
sha256 = "778ed059ad37c3373c22adcb5c200cbbca72b370dd4de93379deb8325c0045cb",
127+
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/4.5.0/rules_nodejs-4.5.0.tar.gz"],
128128
)
129129

130130
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "npm_install")

java/src/org/openqa/selenium/grid/server/BaseServerFlags.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public class BaseServerFlags implements HasRoles {
4242
@ConfigValue(section = SERVER_SECTION, name = "host", example = "\"localhost\"")
4343
private String host;
4444

45+
@Parameter(
46+
names = "--bind-host",
47+
description = "Whether the server should bind to the host address/name, or only use it to" +
48+
" report its reachable url. Helpful in complex network topologies where the" +
49+
" server cannot report itself with the current IP/hostname but rather an" +
50+
" external IP or hostname (e.g. inside a Docker container).",
51+
arity = 1)
52+
@ConfigValue(section = SERVER_SECTION, name = "bind-host", example = "true")
53+
private Boolean bindHost = true;
54+
4555
@Parameter(
4656
description = "Port to listen on. There is no default as this parameter is used by "
4757
+ "different components, for example Router/Hub/Standalone will use 4444 and "

java/src/org/openqa/selenium/grid/server/BaseServerOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ public boolean getAllowCORS() {
115115
return config.getBool(SERVER_SECTION, "allow-cors").orElse(false);
116116
}
117117

118+
public boolean getBindHost() {
119+
return config.getBool(SERVER_SECTION, "bind-host").orElse(true);
120+
}
121+
118122
public boolean isSecure() {
119123
return config.get(SERVER_SECTION, "https-private-key").isPresent()
120124
&& config.get(SERVER_SECTION, "https-certificate").isPresent();

java/src/org/openqa/selenium/netty/server/NettyServer.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@
1717

1818
package org.openqa.selenium.netty.server;
1919

20-
import java.net.InetSocketAddress;
20+
import org.openqa.selenium.grid.server.BaseServerOptions;
21+
import org.openqa.selenium.grid.server.Server;
22+
import org.openqa.selenium.internal.Require;
23+
import org.openqa.selenium.remote.AddWebDriverSpecHeaders;
24+
import org.openqa.selenium.remote.ErrorFilter;
25+
import org.openqa.selenium.remote.http.HttpHandler;
26+
import org.openqa.selenium.remote.http.Message;
27+
2128
import io.netty.bootstrap.ServerBootstrap;
2229
import io.netty.channel.Channel;
2330
import io.netty.channel.EventLoopGroup;
@@ -30,31 +37,27 @@
3037
import io.netty.handler.ssl.util.SelfSignedCertificate;
3138
import io.netty.util.internal.logging.InternalLoggerFactory;
3239
import io.netty.util.internal.logging.JdkLoggerFactory;
33-
import org.openqa.selenium.remote.AddWebDriverSpecHeaders;
34-
import org.openqa.selenium.grid.server.BaseServerOptions;
35-
import org.openqa.selenium.grid.server.Server;
36-
import org.openqa.selenium.remote.ErrorFilter;
37-
import org.openqa.selenium.internal.Require;
38-
import org.openqa.selenium.remote.http.HttpHandler;
39-
import org.openqa.selenium.remote.http.Message;
4040

41-
import javax.net.ssl.SSLException;
4241
import java.io.IOException;
4342
import java.io.UncheckedIOException;
4443
import java.net.BindException;
44+
import java.net.InetSocketAddress;
4545
import java.net.MalformedURLException;
4646
import java.net.URL;
4747
import java.security.cert.CertificateException;
4848
import java.util.Optional;
4949
import java.util.function.BiFunction;
5050
import java.util.function.Consumer;
5151

52+
import javax.net.ssl.SSLException;
53+
5254
public class NettyServer implements Server<NettyServer> {
5355

5456
private final EventLoopGroup bossGroup;
5557
private final EventLoopGroup workerGroup;
5658
private final int port;
5759
private final String host;
60+
private final boolean bindHost;
5861
private final URL externalUrl;
5962
private final HttpHandler handler;
6063
private final BiFunction<String, Consumer<Message>, Optional<Consumer<Message>>> websocketHandler;
@@ -106,6 +109,7 @@ public NettyServer(
106109

107110
port = options.getPort();
108111
host = options.getHostname().orElse("0.0.0.0");
112+
bindHost = options.getBindHost();
109113
allowCors = options.getAllowCORS();
110114

111115
try {
@@ -150,7 +154,11 @@ public NettyServer start() {
150154
.childHandler(new SeleniumHttpInitializer(sslCtx, handler, websocketHandler, allowCors));
151155

152156
try {
153-
channel = b.bind(new InetSocketAddress(host, port)).sync().channel();
157+
// Using a flag to avoid binding to the host, useful in environments like Docker,
158+
// where the "host" value can be the IP of the Docker host machine, which cannot
159+
// be bind inside the container.
160+
channel = bindHost ? b.bind(new InetSocketAddress(host, port)).sync().channel() :
161+
b.bind(port).sync().channel();
154162
} catch (InterruptedException e) {
155163
Thread.currentThread().interrupt();
156164
throw new UncheckedIOException(new IOException("Start up interrupted", e));

java/test/org/openqa/selenium/firefox/BUILD.bazel

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ java_selenium_test_suite(
5757
"//third_party/firebug:firebug-1.5.0-fx.xpi",
5858
"//third_party/firebug:mooltipass-1.1.87.xpi",
5959
],
60-
tags = [
61-
"selenium-remote",
62-
],
6360
deps = [
6461
"//java/src/org/openqa/selenium/firefox",
6562
"//java/src/org/openqa/selenium/remote",

java/test/org/openqa/selenium/grid/gridui/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ java_selenium_test_suite(
88
browsers = [
99
"firefox",
1010
],
11+
tags = [
12+
"selenium-remote",
13+
],
1114
deps = [
1215
"//java/src/org/openqa/selenium:core",
1316
"//java/src/org/openqa/selenium/grid",

java/test/org/openqa/selenium/grid/router/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ java_selenium_test_suite(
4141
"firefox",
4242
"edge",
4343
],
44+
tags = [
45+
"selenium-remote",
46+
],
4447
javacopts = [
4548
"--release",
4649
"11",

java/test/org/openqa/selenium/grid/server/BaseServerOptionsTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,33 @@
1717

1818
package org.openqa.selenium.grid.server;
1919

20+
import static org.assertj.core.api.Assertions.assertThat;
21+
2022
import org.junit.Test;
2123
import org.openqa.selenium.grid.config.MapConfig;
2224

2325
import java.util.Map;
2426

25-
import static org.assertj.core.api.Assertions.assertThat;
26-
2727
public class BaseServerOptionsTest {
2828

2929
@Test
3030
public void readingThePortTwiceShouldGiveTheSameResult() {
31-
BaseServerOptions options = new BaseServerOptions(new MapConfig(Map.of("server", Map.of("port", -1))));
31+
BaseServerOptions options = new BaseServerOptions(
32+
new MapConfig(Map.of("server", Map.of("port", -1))));
3233

3334
int first = options.getPort();
3435
int second = options.getPort();
3536

3637
assertThat(first).isEqualTo(second);
3738
}
3839

40+
@Test
41+
public void serverConfigBindsToHostByDefault() {
42+
BaseServerOptions options = new BaseServerOptions(
43+
new MapConfig(Map.of("server", Map.of("port", 4444))));
44+
45+
assertThat(options.getBindHost()).isEqualTo(true);
46+
}
47+
48+
3949
}

java/test/org/openqa/selenium/netty/server/NettyServerTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static org.assertj.core.api.Assertions.assertThat;
2121
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertFalse;
2223
import static org.junit.Assert.assertNull;
2324
import static org.junit.Assert.assertTrue;
2425
import static org.openqa.selenium.remote.http.Contents.utf8String;
@@ -107,7 +108,6 @@ public void shouldAllowCORS() {
107108
BaseServerOptions options = new BaseServerOptions(cfg);
108109
assertTrue("Allow CORS should be enabled", options.getAllowCORS());
109110

110-
// TODO: Server setup
111111
Server<?> server = new NettyServer(
112112
options,
113113
req -> new HttpResponse()
@@ -126,6 +126,22 @@ public void shouldAllowCORS() {
126126
response.getHeader("Access-Control-Allow-Origin"));
127127
}
128128

129+
@Test
130+
public void shouldNotBindToHost() {
131+
Config cfg = new CompoundConfig(
132+
new MapConfig(ImmutableMap.of("server", ImmutableMap.of(
133+
"bind-host", "false", "host", "anyRandomHost"))));
134+
BaseServerOptions options = new BaseServerOptions(cfg);
135+
assertFalse("Bind to host should be disabled", options.getBindHost());
136+
137+
Server<?> server = new NettyServer(
138+
options,
139+
req -> new HttpResponse()
140+
).start();
141+
142+
assertEquals("anyRandomHost", server.getUrl().getHost());
143+
}
144+
129145
private void outputHeaders(HttpResponse res) {
130146
res.getHeaderNames()
131147
.forEach(name ->

0 commit comments

Comments
 (0)