Skip to content

Commit

Permalink
[java] Restoring ability to create new RemoteWebDriver with default r…
Browse files Browse the repository at this point in the history
…emote server address or the address specified by system property "webdriver.remote.server"
  • Loading branch information
barancev committed Feb 2, 2021
1 parent 6c3bf3d commit bb48c13
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Expand Up @@ -33,7 +33,6 @@
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;

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

public HttpCommandExecutor(URL addressOfRemoteServer) {
this(emptyMap(), addressOfRemoteServer);
this(emptyMap(), Require.nonNull("Remote server address", addressOfRemoteServer));
}

public HttpCommandExecutor(ClientConfig config) {
Expand All @@ -76,7 +75,9 @@ public HttpCommandExecutor(
Map<String, CommandInfo> additionalCommands,
URL addressOfRemoteServer)
{
this(additionalCommands, addressOfRemoteServer, defaultClientFactory);
this(additionalCommands,
Require.nonNull("Remote server address", addressOfRemoteServer),
defaultClientFactory);
}

public HttpCommandExecutor(
Expand All @@ -85,7 +86,8 @@ public HttpCommandExecutor(
HttpClient.Factory httpClientFactory)
{
this(additionalCommands,
ClientConfig.defaultConfig().baseUrl(addressOfRemoteServer),
ClientConfig.defaultConfig()
.baseUrl(Require.nonNull("Remote server address", addressOfRemoteServer)),
httpClientFactory);
}

Expand All @@ -94,18 +96,7 @@ public HttpCommandExecutor(
ClientConfig config,
HttpClient.Factory httpClientFactory)
{
try {
if (config.baseUri() != null) {
remoteServer = config.baseUrl();
} else {
remoteServer = new URL(
System.getProperty("webdriver.remote.server", "http://localhost:4444/"));
config = config.baseUrl(remoteServer);
}
} catch (MalformedURLException e) {
throw new WebDriverException(e);
}

remoteServer = Require.nonNull("Remote server address", config.baseUrl());
this.additionalCommands = additionalCommands;
this.httpClientFactory = httpClientFactory;
this.client = httpClientFactory.createClient(config);
Expand Down
11 changes: 10 additions & 1 deletion java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java
Expand Up @@ -64,6 +64,7 @@
import org.openqa.selenium.virtualauthenticator.VirtualAuthenticator;
import org.openqa.selenium.virtualauthenticator.VirtualAuthenticatorOptions;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.Base64;
Expand Down Expand Up @@ -129,8 +130,16 @@ protected RemoteWebDriver() {
this.capabilities = init(new ImmutableCapabilities());
}

private static URL getDefaultServerURL() {
try {
return new URL(System.getProperty("webdriver.remote.server", "http://localhost:4444/"));
} catch (MalformedURLException e) {
throw new WebDriverException(e);
}
}

public RemoteWebDriver(Capabilities capabilities) {
this((URL) null, capabilities);
this(getDefaultServerURL(), capabilities);
}

public RemoteWebDriver(URL remoteAddress, Capabilities capabilities) {
Expand Down

0 comments on commit bb48c13

Please sign in to comment.