Skip to content

Commit bb48c13

Browse files
committed
[java] Restoring ability to create new RemoteWebDriver with default remote server address or the address specified by system property "webdriver.remote.server"
1 parent 6c3bf3d commit bb48c13

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

java/client/src/org/openqa/selenium/remote/HttpCommandExecutor.java

+7-16
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.openqa.selenium.remote.http.HttpResponse;
3434

3535
import java.io.IOException;
36-
import java.net.MalformedURLException;
3736
import java.net.URL;
3837
import java.util.Map;
3938

@@ -58,7 +57,7 @@ public class HttpCommandExecutor implements CommandExecutor, NeedsLocalLogs {
5857
private LocalLogs logs = LocalLogs.getNullLogger();
5958

6059
public HttpCommandExecutor(URL addressOfRemoteServer) {
61-
this(emptyMap(), addressOfRemoteServer);
60+
this(emptyMap(), Require.nonNull("Remote server address", addressOfRemoteServer));
6261
}
6362

6463
public HttpCommandExecutor(ClientConfig config) {
@@ -76,7 +75,9 @@ public HttpCommandExecutor(
7675
Map<String, CommandInfo> additionalCommands,
7776
URL addressOfRemoteServer)
7877
{
79-
this(additionalCommands, addressOfRemoteServer, defaultClientFactory);
78+
this(additionalCommands,
79+
Require.nonNull("Remote server address", addressOfRemoteServer),
80+
defaultClientFactory);
8081
}
8182

8283
public HttpCommandExecutor(
@@ -85,7 +86,8 @@ public HttpCommandExecutor(
8586
HttpClient.Factory httpClientFactory)
8687
{
8788
this(additionalCommands,
88-
ClientConfig.defaultConfig().baseUrl(addressOfRemoteServer),
89+
ClientConfig.defaultConfig()
90+
.baseUrl(Require.nonNull("Remote server address", addressOfRemoteServer)),
8991
httpClientFactory);
9092
}
9193

@@ -94,18 +96,7 @@ public HttpCommandExecutor(
9496
ClientConfig config,
9597
HttpClient.Factory httpClientFactory)
9698
{
97-
try {
98-
if (config.baseUri() != null) {
99-
remoteServer = config.baseUrl();
100-
} else {
101-
remoteServer = new URL(
102-
System.getProperty("webdriver.remote.server", "http://localhost:4444/"));
103-
config = config.baseUrl(remoteServer);
104-
}
105-
} catch (MalformedURLException e) {
106-
throw new WebDriverException(e);
107-
}
108-
99+
remoteServer = Require.nonNull("Remote server address", config.baseUrl());
109100
this.additionalCommands = additionalCommands;
110101
this.httpClientFactory = httpClientFactory;
111102
this.client = httpClientFactory.createClient(config);

java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.openqa.selenium.virtualauthenticator.VirtualAuthenticator;
6565
import org.openqa.selenium.virtualauthenticator.VirtualAuthenticatorOptions;
6666

67+
import java.net.MalformedURLException;
6768
import java.net.URL;
6869
import java.time.Duration;
6970
import java.util.Base64;
@@ -129,8 +130,16 @@ protected RemoteWebDriver() {
129130
this.capabilities = init(new ImmutableCapabilities());
130131
}
131132

133+
private static URL getDefaultServerURL() {
134+
try {
135+
return new URL(System.getProperty("webdriver.remote.server", "http://localhost:4444/"));
136+
} catch (MalformedURLException e) {
137+
throw new WebDriverException(e);
138+
}
139+
}
140+
132141
public RemoteWebDriver(Capabilities capabilities) {
133-
this((URL) null, capabilities);
142+
this(getDefaultServerURL(), capabilities);
134143
}
135144

136145
public RemoteWebDriver(URL remoteAddress, Capabilities capabilities) {

0 commit comments

Comments
 (0)