Skip to content

Commit 02e3398

Browse files
committed
Revert "[java] Implementing ability to specify command execution timeout in RemoteWebDriver"
This reverts commit 8be1107.
1 parent 8098753 commit 02e3398

File tree

10 files changed

+80
-186
lines changed

10 files changed

+80
-186
lines changed

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

-6
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,9 @@
1818
package org.openqa.selenium.remote;
1919

2020
import java.io.IOException;
21-
import java.time.Duration;
2221

2322
@FunctionalInterface
2423
public interface CommandExecutor {
2524

2625
Response execute(Command command) throws IOException;
27-
28-
default void setCommandExecutionTimeout(Duration timeout) {
29-
throw new UnsupportedOperationException(
30-
"This command executor does not allow to change command execution timeout");
31-
}
3226
}

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

+11-20
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.io.IOException;
3535
import java.net.MalformedURLException;
3636
import java.net.URL;
37-
import java.time.Duration;
3837
import java.util.Map;
3938

4039
import static java.util.Collections.emptyMap;
@@ -69,22 +68,19 @@ public HttpCommandExecutor(URL addressOfRemoteServer) {
6968
* @param addressOfRemoteServer URL of remote end Selenium server
7069
*/
7170
public HttpCommandExecutor(
72-
Map<String, CommandInfo> additionalCommands,
73-
URL addressOfRemoteServer)
74-
{
71+
Map<String, CommandInfo> additionalCommands,
72+
URL addressOfRemoteServer) {
7573
this(additionalCommands, addressOfRemoteServer, defaultClientFactory);
7674
}
7775

7876
public HttpCommandExecutor(
79-
Map<String, CommandInfo> additionalCommands,
80-
URL addressOfRemoteServer,
81-
HttpClient.Factory httpClientFactory)
82-
{
77+
Map<String, CommandInfo> additionalCommands,
78+
URL addressOfRemoteServer,
79+
HttpClient.Factory httpClientFactory) {
8380
try {
8481
remoteServer = addressOfRemoteServer == null
85-
? new URL(System.getProperty("webdriver.remote.server",
86-
"http://localhost:4444/"))
87-
: addressOfRemoteServer;
82+
? new URL(System.getProperty("webdriver.remote.server", "http://localhost:4444/"))
83+
: addressOfRemoteServer;
8884
} catch (MalformedURLException e) {
8985
throw new WebDriverException(e);
9086
}
@@ -130,7 +126,7 @@ public Response execute(Command command) throws IOException {
130126
if (!GET_ALL_SESSIONS.equals(command.getName())
131127
&& !NEW_SESSION.equals(command.getName())) {
132128
throw new NoSuchSessionException(
133-
"Session ID is null. Using WebDriver after calling quit()?");
129+
"Session ID is null. Using WebDriver after calling quit()?");
134130
}
135131
}
136132

@@ -153,7 +149,7 @@ public Response execute(Command command) throws IOException {
153149

154150
if (commandCodec == null || responseCodec == null) {
155151
throw new WebDriverException(
156-
"No command or response codec has been defined. Unable to proceed");
152+
"No command or response codec has been defined. Unable to proceed");
157153
}
158154

159155
HttpRequest httpRequest = commandCodec.encode(command);
@@ -184,15 +180,10 @@ public Response execute(Command command) throws IOException {
184180
} catch (UnsupportedCommandException e) {
185181
if (e.getMessage() == null || "".equals(e.getMessage())) {
186182
throw new UnsupportedOperationException(
187-
"No information from server. Command name was: " + command.getName(),
188-
e.getCause());
183+
"No information from server. Command name was: " + command.getName(),
184+
e.getCause());
189185
}
190186
throw e;
191187
}
192188
}
193-
194-
@Override
195-
public synchronized void setCommandExecutionTimeout(Duration timeout) {
196-
client.setReadTimeout(timeout);
197-
}
198189
}

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

+45-52
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,6 @@ protected void setCommandExecutor(CommandExecutor executor) {
279279
this.executor = executor;
280280
}
281281

282-
public synchronized void setCommandExecutionTimeout(Duration timeout) {
283-
executor.setCommandExecutionTimeout(timeout);
284-
}
285-
286282
@Override
287283
public Capabilities getCapabilities() {
288284
return capabilities;
@@ -320,10 +316,9 @@ public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException
320316
String base64EncodedPng = new String((byte[]) result, UTF_8);
321317
return outputType.convertFromBase64Png(base64EncodedPng);
322318
} else {
323-
throw new RuntimeException(String.format(
324-
"Unexpected result for %s command: %s",
325-
DriverCommand.SCREENSHOT,
326-
result == null ? "null" : result.getClass().getName() + " instance"));
319+
throw new RuntimeException(String.format("Unexpected result for %s command: %s",
320+
DriverCommand.SCREENSHOT,
321+
result == null ? "null" : result.getClass().getName() + " instance"));
327322
}
328323
}
329324

@@ -443,15 +438,14 @@ public String getWindowHandle() {
443438
public Object executeScript(String script, Object... args) {
444439
if (!isJavascriptEnabled()) {
445440
throw new UnsupportedOperationException(
446-
"You must be using an underlying instance of WebDriver that supports executing javascript");
441+
"You must be using an underlying instance of WebDriver that supports executing javascript");
447442
}
448443

449444
// Escape the quote marks
450445
script = script.replaceAll("\"", "\\\"");
451446

452-
List<Object> convertedArgs = Stream.of(args)
453-
.map(new WebElementToJsonConverter())
454-
.collect(Collectors.toList());
447+
List<Object> convertedArgs = Stream.of(args).map(new WebElementToJsonConverter()).collect(
448+
Collectors.toList());
455449

456450
return execute(DriverCommand.EXECUTE_SCRIPT(script, convertedArgs)).getValue();
457451
}
@@ -460,15 +454,14 @@ public Object executeScript(String script, Object... args) {
460454
public Object executeAsyncScript(String script, Object... args) {
461455
if (!isJavascriptEnabled()) {
462456
throw new UnsupportedOperationException("You must be using an underlying instance of " +
463-
"WebDriver that supports executing javascript");
457+
"WebDriver that supports executing javascript");
464458
}
465459

466460
// Escape the quote marks
467461
script = script.replaceAll("\"", "\\\"");
468462

469-
List<Object> convertedArgs = Stream.of(args)
470-
.map(new WebElementToJsonConverter())
471-
.collect(Collectors.toList());
463+
List<Object> convertedArgs = Stream.of(args).map(new WebElementToJsonConverter()).collect(
464+
Collectors.toList());
472465

473466
return execute(DriverCommand.EXECUTE_ASYNC_SCRIPT(script, convertedArgs)).getValue();
474467
}
@@ -603,15 +596,15 @@ public Mouse getMouse() {
603596

604597
@Override
605598
public VirtualAuthenticator addVirtualAuthenticator(VirtualAuthenticatorOptions options) {
606-
String authenticatorId = (String) execute(
607-
DriverCommand.ADD_VIRTUAL_AUTHENTICATOR, options.toMap()).getValue();
599+
String authenticatorId = (String)
600+
execute(DriverCommand.ADD_VIRTUAL_AUTHENTICATOR, options.toMap()).getValue();
608601
return new RemoteVirtualAuthenticator(authenticatorId);
609602
}
610603

611604
@Override
612605
public void removeVirtualAuthenticator(VirtualAuthenticator authenticator) {
613606
execute(DriverCommand.REMOVE_VIRTUAL_AUTHENTICATOR,
614-
ImmutableMap.of("authenticatorId", authenticator.getId()));
607+
ImmutableMap.of("authenticatorId", authenticator.getId()));
615608
}
616609

617610
/**
@@ -694,24 +687,24 @@ public Set<Cookie> getCookies() {
694687
}
695688

696689
((Collection<?>) returned).stream()
697-
.map(o -> (Map<String, Object>) o)
698-
.map(rawCookie -> {
699-
// JSON object keys are defined in
700-
// https://w3c.github.io/webdriver/#dfn-table-for-cookie-conversion.
701-
Cookie.Builder builder =
702-
new Cookie.Builder((String) rawCookie.get("name"), (String) rawCookie.get("value"))
703-
.path((String) rawCookie.get("path"))
704-
.domain((String) rawCookie.get("domain"))
705-
.isSecure(rawCookie.containsKey("secure") && (Boolean) rawCookie.get("secure"))
706-
.isHttpOnly(
707-
rawCookie.containsKey("httpOnly") && (Boolean) rawCookie.get("httpOnly"))
708-
.sameSite((String) rawCookie.get("sameSite"));
709-
710-
Number expiryNum = (Number) rawCookie.get("expiry");
711-
builder.expiresOn(expiryNum == null ? null : new Date(SECONDS.toMillis(expiryNum.longValue())));
712-
return builder.build();
713-
})
714-
.forEach(toReturn::add);
690+
.map(o -> (Map<String, Object>) o)
691+
.map(rawCookie -> {
692+
// JSON object keys are defined in
693+
// https://w3c.github.io/webdriver/#dfn-table-for-cookie-conversion.
694+
Cookie.Builder builder =
695+
new Cookie.Builder((String) rawCookie.get("name"), (String) rawCookie.get("value"))
696+
.path((String) rawCookie.get("path"))
697+
.domain((String) rawCookie.get("domain"))
698+
.isSecure(rawCookie.containsKey("secure") && (Boolean) rawCookie.get("secure"))
699+
.isHttpOnly(
700+
rawCookie.containsKey("httpOnly") && (Boolean) rawCookie.get("httpOnly"))
701+
.sameSite((String) rawCookie.get("sameSite"));
702+
703+
Number expiryNum = (Number) rawCookie.get("expiry");
704+
builder.expiresOn(expiryNum == null ? null : new Date(SECONDS.toMillis(expiryNum.longValue())));
705+
return builder.build();
706+
})
707+
.forEach(toReturn::add);
715708

716709
return toReturn;
717710
}
@@ -910,10 +903,10 @@ public WebDriver frame(int frameIndex) {
910903
public WebDriver frame(String frameName) {
911904
String name = frameName.replaceAll("(['\"\\\\#.:;,!?+<>=~*^$|%&@`{}\\-/\\[\\]\\(\\)])", "\\\\$1");
912905
List<WebElement> frameElements = RemoteWebDriver.this.findElements(
913-
By.cssSelector("frame[name='" + name + "'],iframe[name='" + name + "']"));
906+
By.cssSelector("frame[name='" + name + "'],iframe[name='" + name + "']"));
914907
if (frameElements.size() == 0) {
915908
frameElements = RemoteWebDriver.this.findElements(
916-
By.cssSelector("frame#" + name + ",iframe#" + name));
909+
By.cssSelector("frame#" + name + ",iframe#" + name));
917910
}
918911
if (frameElements.size() == 0) {
919912
throw new NoSuchFrameException("No frame element found by name or id " + frameName);
@@ -1035,16 +1028,16 @@ public String getId() {
10351028
@Override
10361029
public void addCredential(Credential credential) {
10371030
execute(DriverCommand.ADD_CREDENTIAL,
1038-
new ImmutableMap.Builder<String, Object>()
1039-
.putAll(credential.toMap())
1040-
.put("authenticatorId", id)
1041-
.build());
1031+
new ImmutableMap.Builder<String, Object>()
1032+
.putAll(credential.toMap())
1033+
.put("authenticatorId", id)
1034+
.build());
10421035
}
10431036

10441037
@Override
10451038
public List<Credential> getCredentials() {
1046-
List<Map<String, Object>> response = (List<Map<String, Object>>) execute(
1047-
DriverCommand.GET_CREDENTIALS, ImmutableMap.of("authenticatorId", id)).getValue();
1039+
List<Map<String, Object>> response = (List<Map<String, Object>>)
1040+
execute(DriverCommand.GET_CREDENTIALS, ImmutableMap.of("authenticatorId", id)).getValue();
10481041
return response.stream().map(Credential::fromMap).collect(Collectors.toList());
10491042
}
10501043

@@ -1056,7 +1049,7 @@ public void removeCredential(byte[] credentialId) {
10561049
@Override
10571050
public void removeCredential(String credentialId) {
10581051
execute(DriverCommand.REMOVE_CREDENTIAL,
1059-
ImmutableMap.of("authenticatorId", id, "credentialId", credentialId));
1052+
ImmutableMap.of("authenticatorId", id, "credentialId", credentialId));
10601053
}
10611054

10621055
@Override
@@ -1067,7 +1060,7 @@ public void removeAllCredentials() {
10671060
@Override
10681061
public void setUserVerified(boolean verified) {
10691062
execute(DriverCommand.SET_USER_VERIFIED,
1070-
ImmutableMap.of("authenticatorId", id, "isUserVerified", verified));
1063+
ImmutableMap.of("authenticatorId", id, "isUserVerified", verified));
10711064
}
10721065
}
10731066

@@ -1094,10 +1087,10 @@ public String toString() {
10941087
}
10951088

10961089
return String.format(
1097-
"%s: %s on %s (%s)",
1098-
getClass().getSimpleName(),
1099-
caps.getBrowserName(),
1100-
platform,
1101-
getSessionId());
1090+
"%s: %s on %s (%s)",
1091+
getClass().getSimpleName(),
1092+
caps.getBrowserName(),
1093+
platform,
1094+
getSessionId());
11021095
}
11031096
}

java/client/src/org/openqa/selenium/remote/http/HttpClient.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.openqa.selenium.remote.http;
1919

2020
import java.net.URL;
21-
import java.time.Duration;
2221
import java.util.ServiceLoader;
2322
import java.util.Set;
2423
import java.util.stream.Collectors;
@@ -35,10 +34,6 @@ public interface HttpClient extends HttpHandler {
3534

3635
WebSocket openSocket(HttpRequest request, WebSocket.Listener listener);
3736

38-
default void setReadTimeout(Duration timeout) {
39-
throw new UnsupportedOperationException("This client does not allow to change read timeout");
40-
}
41-
4237
interface Factory {
4338

4439
/**
@@ -52,15 +47,15 @@ interface Factory {
5247
static Factory create(String name) {
5348
ServiceLoader<HttpClient.Factory> loader = ServiceLoader.load(HttpClient.Factory.class);
5449
Set<Factory> factories = StreamSupport.stream(loader.spliterator(), true)
55-
.filter(p -> p.getClass().isAnnotationPresent(HttpClientName.class))
56-
.filter(p -> name.equals(p.getClass().getAnnotation(HttpClientName.class).value()))
57-
.collect(Collectors.toSet());
50+
.filter(p -> p.getClass().isAnnotationPresent(HttpClientName.class))
51+
.filter(p -> name.equals(p.getClass().getAnnotation(HttpClientName.class).value()))
52+
.collect(Collectors.toSet());
5853
if (factories.isEmpty()) {
5954
throw new IllegalArgumentException("Unknown HttpClient factory " + name);
6055
}
6156
if (factories.size() > 1) {
6257
throw new IllegalStateException(String.format(
63-
"There are multiple HttpClient factories by name %s, check your classpath", name));
58+
"There are multiple HttpClient factories by name %s, check your classpath", name));
6459
}
6560
return factories.iterator().next();
6661
}

java/client/src/org/openqa/selenium/remote/http/HttpHandler.java

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.openqa.selenium.remote.http;
1919

2020
import java.io.UncheckedIOException;
21-
import java.time.Duration;
2221

2322
@FunctionalInterface
2423
public interface HttpHandler {

0 commit comments

Comments
 (0)