[java] use the W3C state to detect errors
diff --git a/java/src/org/openqa/selenium/remote/ErrorCodes.java b/java/src/org/openqa/selenium/remote/ErrorCodes.java
index 619bac0..a32b758 100644
--- a/java/src/org/openqa/selenium/remote/ErrorCodes.java
+++ b/java/src/org/openqa/selenium/remote/ErrorCodes.java
@@ -173,7 +173,7 @@ public class ErrorCodes {
405,
UnsupportedCommandException.class,
false,
- true),
+ false),
new KnownError(
METHOD_NOT_ALLOWED,
"unsupported operation",
diff --git a/java/src/org/openqa/selenium/remote/ErrorHandler.java b/java/src/org/openqa/selenium/remote/ErrorHandler.java
index 689af8e..59a52dd 100644
--- a/java/src/org/openqa/selenium/remote/ErrorHandler.java
+++ b/java/src/org/openqa/selenium/remote/ErrorHandler.java
@@ -17,8 +17,6 @@
package org.openqa.selenium.remote;
-import static org.openqa.selenium.remote.ErrorCodes.SUCCESS;
-
import java.lang.reflect.Constructor;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -82,7 +80,7 @@ public void setIncludeServerErrors(boolean includeServerErrors) {
@SuppressWarnings("unchecked")
public Response throwIfResponseFailed(Response response, long duration) throws RuntimeException {
- if (response.getStatus() == null || response.getStatus() == SUCCESS) {
+ if ("success".equals(response.getState())) {
return response;
}
diff --git a/java/src/org/openqa/selenium/remote/codec/w3c/W3CHttpResponseCodec.java b/java/src/org/openqa/selenium/remote/codec/w3c/W3CHttpResponseCodec.java
index a666e7a..c525b0c 100644
--- a/java/src/org/openqa/selenium/remote/codec/w3c/W3CHttpResponseCodec.java
+++ b/java/src/org/openqa/selenium/remote/codec/w3c/W3CHttpResponseCodec.java
@@ -90,10 +90,12 @@ public Response decode(HttpResponse encodedResponse) {
if (!encodedResponse.isSuccessful()) {
LOG.fine("Processing an error");
if (HTTP_BAD_METHOD == encodedResponse.getStatus()) {
+ response.setState("unknown command");
response.setStatus(ErrorCodes.UNKNOWN_COMMAND);
response.setValue(content);
} else if (HTTP_GATEWAY_TIMEOUT == encodedResponse.getStatus()
|| HTTP_BAD_GATEWAY == encodedResponse.getStatus()) {
+ response.setState("unknown error");
response.setStatus(ErrorCodes.UNHANDLED_ERROR);
response.setValue(content);
} else {
diff --git a/java/test/org/openqa/selenium/remote/AugmenterTest.java b/java/test/org/openqa/selenium/remote/AugmenterTest.java
index 8674dd7..55d4e12 100644
--- a/java/test/org/openqa/selenium/remote/AugmenterTest.java
+++ b/java/test/org/openqa/selenium/remote/AugmenterTest.java
@@ -308,6 +308,7 @@ protected StubExecutor(Capabilities capabilities) {
public Response execute(Command command) {
if (DriverCommand.NEW_SESSION.equals(command.getName())) {
Response response = new Response(new SessionId("foo"));
+ response.setState("success");
response.setValue(capabilities.asMap());
return response;
}
@@ -316,6 +317,7 @@ public Response execute(Command command) {
if (possibleMatch.commandName.equals(command.getName())
&& possibleMatch.args.equals(command.getParameters())) {
Response response = new Response(new SessionId("foo"));
+ response.setState("success");
response.setValue(possibleMatch.returnValue);
return response;
}
diff --git a/java/test/org/openqa/selenium/remote/ErrorHandlerTest.java b/java/test/org/openqa/selenium/remote/ErrorHandlerTest.java
index e30eb20..c4e9e18 100644
--- a/java/test/org/openqa/selenium/remote/ErrorHandlerTest.java
+++ b/java/test/org/openqa/selenium/remote/ErrorHandlerTest.java
@@ -480,6 +480,7 @@ private Response createResponse(int status) {
private Response createResponse(int status, Object value) {
Response response = new Response();
response.setStatus(status);
+ response.setState(new ErrorCodes().toState(status));
response.setValue(value);
return response;
}
diff --git a/java/test/org/openqa/selenium/remote/RemoteWebDriverInitializationTest.java b/java/test/org/openqa/selenium/remote/RemoteWebDriverInitializationTest.java
index 2465151..111cac6 100644
--- a/java/test/org/openqa/selenium/remote/RemoteWebDriverInitializationTest.java
+++ b/java/test/org/openqa/selenium/remote/RemoteWebDriverInitializationTest.java
@@ -167,6 +167,7 @@ void canHandleUnknownPlatformNameAndFallsBackToUnix() {
void canHandleNonStandardCapabilitiesReturnedByRemoteEnd() throws IOException {
Response resp = new Response();
resp.setSessionId(UUID.randomUUID().toString());
+ resp.setState("success");
resp.setValue(ImmutableMap.of("platformName", "xxx"));
CommandExecutor executor = mock(CommandExecutor.class);
when(executor.execute(any())).thenReturn(resp);
diff --git a/java/test/org/openqa/selenium/remote/WebDriverFixture.java b/java/test/org/openqa/selenium/remote/WebDriverFixture.java
index 3ccb00b07..0bf3c47 100644
--- a/java/test/org/openqa/selenium/remote/WebDriverFixture.java
+++ b/java/test/org/openqa/selenium/remote/WebDriverFixture.java
@@ -156,6 +156,7 @@ private boolean areEqual(Object left, Object right) {
public static Function<Command, Response> valueResponder(Object value) {
return cmd -> {
Response response = new Response();
+ response.setState("success");
response.setValue(value);
response.setSessionId(cmd.getSessionId() != null ? cmd.getSessionId().toString() : null);
return response;
@@ -181,6 +182,7 @@ public static Function<Command, Response> errorResponder(String state, Object va
Collection<Capabilities> capabilities =
(Collection<Capabilities>) cmd.getParameters().get("capabilities");
+ response.setState("success");
response.setValue(
capabilities.iterator().next().asMap().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toString())));
diff --git a/java/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java b/java/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java
index 3cb976e..50d396b 100644
--- a/java/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java
+++ b/java/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java
@@ -62,6 +62,7 @@ public void createMocks() {
void shouldIncludeRemoteInfoForWrappedDriverTimeout() throws IOException {
Capabilities caps = new MutableCapabilities();
Response response = new Response(new SessionId("foo"));
+ response.setState("success");
response.setValue(caps.asMap());
CommandExecutor executor = mock(CommandExecutor.class);
when(executor.execute(any(Command.class))).thenReturn(response);