Skip to content

Commit 347dee3

Browse files
committed
an attempt at fixing the error codes, with some tests
1 parent 8712020 commit 347dee3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public class ErrorCodes {
9393
public static final int MOVE_TARGET_OUT_OF_BOUNDS = 34;
9494
public static final int INVALID_XPATH_SELECTOR = 51;
9595
public static final int INVALID_XPATH_SELECTOR_RETURN_TYPER = 52;
96+
97+
// json wire protocol doesn't have analogous status codes for
98+
// these new W3C status repsonse 'codes', so making some up!
99+
public static final int ELEMENT_NOT_INTERACTABLE = 60;
100+
96101
// The following error codes are derived straight from HTTP return codes.
97102
public static final int METHOD_NOT_ALLOWED = 405;
98103

@@ -108,8 +113,7 @@ public class ErrorCodes {
108113
.put(400,
109114
ImmutableSortedSet.<StatusTuple>naturalOrder()
110115
.add(new StatusTuple("element not selectable", ELEMENT_NOT_SELECTABLE, ElementNotSelectableException.class))
111-
.add(new StatusTuple("element not interactable", INVALID_ELEMENT_STATE, ElementNotInteractableException.class))
112-
.add(new StatusTuple("element not interactable", ELEMENT_NOT_VISIBLE, ElementNotVisibleException.class))
116+
.add(new StatusTuple("element not interactable", ELEMENT_NOT_INTERACTABLE, ElementNotInteractableException.class))
113117
.add(new StatusTuple("element not visible", ELEMENT_NOT_VISIBLE, ElementNotVisibleException.class))
114118
.add(new StatusTuple("invalid argument", UNHANDLED_ERROR, InvalidArgumentException.class))
115119
.add(new StatusTuple("invalid cookie domain", INVALID_COOKIE_DOMAIN, InvalidCookieDomainException.class))

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,28 @@ public void testShouldStillIncludeScreenshotEvenIfServerSideExceptionsAreDisable
418418
}
419419
}
420420

421+
@Test
422+
public void testInvalidElementStateExceptionIsRaisedForJSONWP() {
423+
try {
424+
handler.throwIfResponseFailed(createResponse(ErrorCodes.INVALID_ELEMENT_STATE), 123);
425+
fail("Should have thrown an InvalidElementStateException");
426+
} catch (InvalidElementStateException iese) {
427+
assertEquals("InvalidElementStateException", iese.getClass().getSimpleName());
428+
assertEquals(ErrorCodes.INVALID_ELEMENT_STATE, new ErrorCodes().toStatusCode(iese));
429+
}
430+
}
431+
432+
@Test
433+
public void testElementNotVisibleStateExceptionIsRaisedForJSONWP() {
434+
try {
435+
handler.throwIfResponseFailed(createResponse(ErrorCodes.ELEMENT_NOT_VISIBLE), 123);
436+
fail("Should have thrown an InvalidElementStateException");
437+
} catch (ElementNotVisibleException enve) {
438+
assertEquals("ElementNotVisibleException", enve.getClass().getSimpleName());
439+
assertEquals(ErrorCodes.ELEMENT_NOT_VISIBLE, new ErrorCodes().toStatusCode(enve));
440+
}
441+
}
442+
421443
private Response createResponse(int status) {
422444
return createResponse(status, null);
423445
}

0 commit comments

Comments
 (0)