|
33 | 33 | import org.junit.Test;
|
34 | 34 | import org.junit.runner.RunWith;
|
35 | 35 | import org.junit.runners.JUnit4;
|
| 36 | +import org.openqa.selenium.ElementNotSelectableException; |
36 | 37 | import org.openqa.selenium.ElementNotVisibleException;
|
| 38 | +import org.openqa.selenium.ImeActivationFailedException; |
| 39 | +import org.openqa.selenium.ImeNotAvailableException; |
37 | 40 | import org.openqa.selenium.InvalidArgumentException;
|
| 41 | +import org.openqa.selenium.InvalidCookieDomainException; |
38 | 42 | import org.openqa.selenium.InvalidElementStateException;
|
39 | 43 | import org.openqa.selenium.InvalidSelectorException;
|
| 44 | +import org.openqa.selenium.NoAlertPresentException; |
40 | 45 | import org.openqa.selenium.NoSuchElementException;
|
41 | 46 | import org.openqa.selenium.NoSuchFrameException;
|
| 47 | +import org.openqa.selenium.NoSuchSessionException; |
42 | 48 | import org.openqa.selenium.NoSuchWindowException;
|
| 49 | +import org.openqa.selenium.ScriptTimeoutException; |
| 50 | +import org.openqa.selenium.SessionNotCreatedException; |
43 | 51 | import org.openqa.selenium.StaleElementReferenceException;
|
| 52 | +import org.openqa.selenium.TimeoutException; |
| 53 | +import org.openqa.selenium.UnableToSetCookieException; |
| 54 | +import org.openqa.selenium.UnhandledAlertException; |
44 | 55 | import org.openqa.selenium.UnsupportedCommandException;
|
| 56 | +import org.openqa.selenium.WebDriver; |
45 | 57 | import org.openqa.selenium.WebDriverException;
|
46 | 58 | import org.openqa.selenium.interactions.InvalidCoordinatesException;
|
| 59 | +import org.openqa.selenium.interactions.MoveTargetOutOfBoundsException; |
47 | 60 |
|
| 61 | +import javafx.util.Pair; |
| 62 | + |
| 63 | +import java.util.ArrayList; |
| 64 | +import java.util.Arrays; |
| 65 | +import java.util.List; |
48 | 66 | import java.util.Map;
|
49 | 67 |
|
50 | 68 | /**
|
@@ -419,24 +437,44 @@ public void testShouldStillIncludeScreenshotEvenIfServerSideExceptionsAreDisable
|
419 | 437 | }
|
420 | 438 |
|
421 | 439 | @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 | + public void testStatusCodesRaisedBackToStatusMatches() { |
| 441 | + List<Pair<Integer, Class>> exceptions = Arrays.asList( |
| 442 | + new Pair(ErrorCodes.NO_SUCH_SESSION, NoSuchSessionException.class), |
| 443 | + new Pair(ErrorCodes.NO_SUCH_ELEMENT, NoSuchElementException.class), |
| 444 | + new Pair(ErrorCodes.NO_SUCH_FRAME, NoSuchFrameException.class), |
| 445 | + new Pair(ErrorCodes.UNKNOWN_COMMAND, UnsupportedCommandException.class), |
| 446 | + new Pair(ErrorCodes.STALE_ELEMENT_REFERENCE, StaleElementReferenceException.class), |
| 447 | + new Pair(ErrorCodes.ELEMENT_NOT_VISIBLE, ElementNotVisibleException.class), |
| 448 | + new Pair(ErrorCodes.INVALID_ELEMENT_STATE, InvalidElementStateException.class), |
| 449 | + new Pair(ErrorCodes.UNHANDLED_ERROR, WebDriverException.class), |
| 450 | + new Pair(ErrorCodes.ELEMENT_NOT_SELECTABLE, ElementNotSelectableException.class), |
| 451 | + new Pair(ErrorCodes.JAVASCRIPT_ERROR, WebDriverException.class), |
| 452 | + new Pair(ErrorCodes.XPATH_LOOKUP_ERROR, InvalidSelectorException.class), |
| 453 | + new Pair(ErrorCodes.TIMEOUT, TimeoutException.class), |
| 454 | + new Pair(ErrorCodes.NO_SUCH_WINDOW, NoSuchWindowException.class), |
| 455 | + new Pair(ErrorCodes.INVALID_COOKIE_DOMAIN, InvalidCookieDomainException.class), |
| 456 | + new Pair(ErrorCodes.UNABLE_TO_SET_COOKIE, UnableToSetCookieException.class), |
| 457 | + new Pair(ErrorCodes.UNEXPECTED_ALERT_PRESENT, UnhandledAlertException.class), |
| 458 | + new Pair(ErrorCodes.NO_ALERT_PRESENT, NoAlertPresentException.class), |
| 459 | + new Pair(ErrorCodes.ASYNC_SCRIPT_TIMEOUT, ScriptTimeoutException.class), |
| 460 | + new Pair(ErrorCodes.INVALID_ELEMENT_COORDINATES, InvalidCoordinatesException.class), |
| 461 | + new Pair(ErrorCodes.IME_NOT_AVAILABLE, ImeNotAvailableException.class), |
| 462 | + new Pair(ErrorCodes.IME_ENGINE_ACTIVATION_FAILED, ImeActivationFailedException.class), |
| 463 | + new Pair(ErrorCodes.INVALID_SELECTOR_ERROR, InvalidSelectorException.class), |
| 464 | + new Pair(ErrorCodes.SESSION_NOT_CREATED, SessionNotCreatedException.class), |
| 465 | + new Pair(ErrorCodes.MOVE_TARGET_OUT_OF_BOUNDS, MoveTargetOutOfBoundsException.class), |
| 466 | + new Pair(ErrorCodes.INVALID_XPATH_SELECTOR, InvalidSelectorException.class), |
| 467 | + new Pair(ErrorCodes.INVALID_XPATH_SELECTOR_RETURN_TYPER, InvalidSelectorException.class) |
| 468 | + ); |
| 469 | + |
| 470 | + for (Pair<Integer, Class> exception : exceptions) { |
| 471 | + try { |
| 472 | + handler.throwIfResponseFailed(createResponse(exception.getKey()), 123); |
| 473 | + fail("Should have thrown an Exception"); |
| 474 | + } catch (Exception e) { |
| 475 | + assertEquals("Checking status code: " + exception.getKey(), exception.getValue().getSimpleName(), e.getClass().getSimpleName()); |
| 476 | + assertEquals(e.getClass().getSimpleName() + " ErrorCodes.toStatusCode", exception.getKey().intValue(), new ErrorCodes().toStatusCode(e)); |
| 477 | + } |
440 | 478 | }
|
441 | 479 | }
|
442 | 480 |
|
|
0 commit comments