Skip to content

Commit fb062a5

Browse files
committed
[java] use the W3C state to detect errors
1 parent 4ffaab1 commit fb062a5

File tree

8 files changed

+11
-4
lines changed

8 files changed

+11
-4
lines changed

java/src/org/openqa/selenium/remote/ErrorCodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public class ErrorCodes {
173173
405,
174174
UnsupportedCommandException.class,
175175
false,
176-
true),
176+
false),
177177
new KnownError(
178178
METHOD_NOT_ALLOWED,
179179
"unsupported operation",

java/src/org/openqa/selenium/remote/ErrorHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package org.openqa.selenium.remote;
1919

20-
import static org.openqa.selenium.remote.ErrorCodes.SUCCESS;
21-
2220
import java.lang.reflect.Constructor;
2321
import java.math.BigDecimal;
2422
import java.math.RoundingMode;
@@ -82,7 +80,7 @@ public void setIncludeServerErrors(boolean includeServerErrors) {
8280

8381
@SuppressWarnings("unchecked")
8482
public Response throwIfResponseFailed(Response response, long duration) throws RuntimeException {
85-
if (response.getStatus() == null || response.getStatus() == SUCCESS) {
83+
if ("success".equals(response.getState())) {
8684
return response;
8785
}
8886

java/src/org/openqa/selenium/remote/codec/w3c/W3CHttpResponseCodec.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ public Response decode(HttpResponse encodedResponse) {
9090
if (!encodedResponse.isSuccessful()) {
9191
LOG.fine("Processing an error");
9292
if (HTTP_BAD_METHOD == encodedResponse.getStatus()) {
93+
response.setState("unknown command");
9394
response.setStatus(ErrorCodes.UNKNOWN_COMMAND);
9495
response.setValue(content);
9596
} else if (HTTP_GATEWAY_TIMEOUT == encodedResponse.getStatus()
9697
|| HTTP_BAD_GATEWAY == encodedResponse.getStatus()) {
98+
response.setState("unknown error");
9799
response.setStatus(ErrorCodes.UNHANDLED_ERROR);
98100
response.setValue(content);
99101
} else {

java/test/org/openqa/selenium/remote/AugmenterTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ protected StubExecutor(Capabilities capabilities) {
308308
public Response execute(Command command) {
309309
if (DriverCommand.NEW_SESSION.equals(command.getName())) {
310310
Response response = new Response(new SessionId("foo"));
311+
response.setState("success");
311312
response.setValue(capabilities.asMap());
312313
return response;
313314
}
@@ -316,6 +317,7 @@ public Response execute(Command command) {
316317
if (possibleMatch.commandName.equals(command.getName())
317318
&& possibleMatch.args.equals(command.getParameters())) {
318319
Response response = new Response(new SessionId("foo"));
320+
response.setState("success");
319321
response.setValue(possibleMatch.returnValue);
320322
return response;
321323
}

java/test/org/openqa/selenium/remote/ErrorHandlerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ private Response createResponse(int status) {
480480
private Response createResponse(int status, Object value) {
481481
Response response = new Response();
482482
response.setStatus(status);
483+
response.setState(new ErrorCodes().toState(status));
483484
response.setValue(value);
484485
return response;
485486
}

java/test/org/openqa/selenium/remote/RemoteWebDriverInitializationTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ void canHandleUnknownPlatformNameAndFallsBackToUnix() {
167167
void canHandleNonStandardCapabilitiesReturnedByRemoteEnd() throws IOException {
168168
Response resp = new Response();
169169
resp.setSessionId(UUID.randomUUID().toString());
170+
resp.setState("success");
170171
resp.setValue(ImmutableMap.of("platformName", "xxx"));
171172
CommandExecutor executor = mock(CommandExecutor.class);
172173
when(executor.execute(any())).thenReturn(resp);

java/test/org/openqa/selenium/remote/WebDriverFixture.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ private boolean areEqual(Object left, Object right) {
156156
public static Function<Command, Response> valueResponder(Object value) {
157157
return cmd -> {
158158
Response response = new Response();
159+
response.setState("success");
159160
response.setValue(value);
160161
response.setSessionId(cmd.getSessionId() != null ? cmd.getSessionId().toString() : null);
161162
return response;
@@ -181,6 +182,7 @@ public static Function<Command, Response> errorResponder(String state, Object va
181182
Collection<Capabilities> capabilities =
182183
(Collection<Capabilities>) cmd.getParameters().get("capabilities");
183184

185+
response.setState("success");
184186
response.setValue(
185187
capabilities.iterator().next().asMap().entrySet().stream()
186188
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toString())));

java/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void createMocks() {
6262
void shouldIncludeRemoteInfoForWrappedDriverTimeout() throws IOException {
6363
Capabilities caps = new MutableCapabilities();
6464
Response response = new Response(new SessionId("foo"));
65+
response.setState("success");
6566
response.setValue(caps.asMap());
6667
CommandExecutor executor = mock(CommandExecutor.class);
6768
when(executor.execute(any(Command.class))).thenReturn(response);

0 commit comments

Comments
 (0)