Skip to content

Commit

Permalink
an attempt at fixing the error codes, with some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeis committed Oct 12, 2016
1 parent 8712020 commit 347dee3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
8 changes: 6 additions & 2 deletions java/client/src/org/openqa/selenium/remote/ErrorCodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public class ErrorCodes {
public static final int MOVE_TARGET_OUT_OF_BOUNDS = 34;
public static final int INVALID_XPATH_SELECTOR = 51;
public static final int INVALID_XPATH_SELECTOR_RETURN_TYPER = 52;

// json wire protocol doesn't have analogous status codes for
// these new W3C status repsonse 'codes', so making some up!
public static final int ELEMENT_NOT_INTERACTABLE = 60;

// The following error codes are derived straight from HTTP return codes.
public static final int METHOD_NOT_ALLOWED = 405;

Expand All @@ -108,8 +113,7 @@ public class ErrorCodes {
.put(400,
ImmutableSortedSet.<StatusTuple>naturalOrder()
.add(new StatusTuple("element not selectable", ELEMENT_NOT_SELECTABLE, ElementNotSelectableException.class))
.add(new StatusTuple("element not interactable", INVALID_ELEMENT_STATE, ElementNotInteractableException.class))
.add(new StatusTuple("element not interactable", ELEMENT_NOT_VISIBLE, ElementNotVisibleException.class))
.add(new StatusTuple("element not interactable", ELEMENT_NOT_INTERACTABLE, ElementNotInteractableException.class))
.add(new StatusTuple("element not visible", ELEMENT_NOT_VISIBLE, ElementNotVisibleException.class))
.add(new StatusTuple("invalid argument", UNHANDLED_ERROR, InvalidArgumentException.class))
.add(new StatusTuple("invalid cookie domain", INVALID_COOKIE_DOMAIN, InvalidCookieDomainException.class))
Expand Down
22 changes: 22 additions & 0 deletions java/client/test/org/openqa/selenium/remote/ErrorHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,28 @@ public void testShouldStillIncludeScreenshotEvenIfServerSideExceptionsAreDisable
}
}

@Test
public void testInvalidElementStateExceptionIsRaisedForJSONWP() {
try {
handler.throwIfResponseFailed(createResponse(ErrorCodes.INVALID_ELEMENT_STATE), 123);
fail("Should have thrown an InvalidElementStateException");
} catch (InvalidElementStateException iese) {
assertEquals("InvalidElementStateException", iese.getClass().getSimpleName());
assertEquals(ErrorCodes.INVALID_ELEMENT_STATE, new ErrorCodes().toStatusCode(iese));
}
}

@Test
public void testElementNotVisibleStateExceptionIsRaisedForJSONWP() {
try {
handler.throwIfResponseFailed(createResponse(ErrorCodes.ELEMENT_NOT_VISIBLE), 123);
fail("Should have thrown an InvalidElementStateException");
} catch (ElementNotVisibleException enve) {
assertEquals("ElementNotVisibleException", enve.getClass().getSimpleName());
assertEquals(ErrorCodes.ELEMENT_NOT_VISIBLE, new ErrorCodes().toStatusCode(enve));
}
}

private Response createResponse(int status) {
return createResponse(status, null);
}
Expand Down

0 comments on commit 347dee3

Please sign in to comment.