Skip to content

Commit c1e405f

Browse files
committed
fix serialization of UnhandledAlertException
fix java warnings
1 parent fbd8529 commit c1e405f

File tree

3 files changed

+44
-26
lines changed

3 files changed

+44
-26
lines changed

java/client/src/org/openqa/selenium/UnhandledAlertException.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package org.openqa.selenium;
1919

20+
import com.google.gson.JsonObject;
21+
import com.google.gson.JsonPrimitive;
22+
2023
public class UnhandledAlertException extends WebDriverException {
2124

2225
private final String alertText;
@@ -36,4 +39,12 @@ public UnhandledAlertException(String message, String alertText) {
3639
public String getAlertText() {
3740
return alertText;
3841
}
42+
43+
public JsonObject toJson() {
44+
JsonObject text = new JsonObject();
45+
text.add("text", new JsonPrimitive(alertText));
46+
JsonObject alert = new JsonObject();
47+
alert.add("alert", text);
48+
return alert;
49+
}
3950
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.openqa.selenium.Cookie;
3333
import org.openqa.selenium.Platform;
3434
import org.openqa.selenium.Proxy;
35+
import org.openqa.selenium.UnhandledAlertException;
3536
import org.openqa.selenium.WebDriverException;
3637
import org.openqa.selenium.logging.LogEntries;
3738
import org.openqa.selenium.logging.LogEntry;
@@ -327,6 +328,12 @@ public void testShouldBeAbleToConvertAWebDriverException() {
327328
verifyStackTraceInJson(raw, stackTrace);
328329
}
329330

331+
@Test
332+
public void testShouldConverUnhandledAlertException() {
333+
RuntimeException clientError = new UnhandledAlertException("unhandled alert", "cheese!");
334+
assertEquals("{\"alert\":{\"text\":\"cheese!\"}}", new BeanToJsonConverter().convert(clientError));
335+
}
336+
330337
@Test
331338
public void testShouldConvertDatesToMillisecondsInUtcTime() {
332339
String jsonStr = new BeanToJsonConverter().convert(new Date(0));

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -439,32 +439,32 @@ public void testShouldStillIncludeScreenshotEvenIfServerSideExceptionsAreDisable
439439
@Test
440440
public void testStatusCodesRaisedBackToStatusMatches() {
441441
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)
442+
new Pair<Integer, Class>(ErrorCodes.NO_SUCH_SESSION, NoSuchSessionException.class),
443+
new Pair<Integer, Class>(ErrorCodes.NO_SUCH_ELEMENT, NoSuchElementException.class),
444+
new Pair<Integer, Class>(ErrorCodes.NO_SUCH_FRAME, NoSuchFrameException.class),
445+
new Pair<Integer, Class>(ErrorCodes.UNKNOWN_COMMAND, UnsupportedCommandException.class),
446+
new Pair<Integer, Class>(ErrorCodes.STALE_ELEMENT_REFERENCE, StaleElementReferenceException.class),
447+
new Pair<Integer, Class>(ErrorCodes.ELEMENT_NOT_VISIBLE, ElementNotVisibleException.class),
448+
new Pair<Integer, Class>(ErrorCodes.INVALID_ELEMENT_STATE, InvalidElementStateException.class),
449+
new Pair<Integer, Class>(ErrorCodes.UNHANDLED_ERROR, WebDriverException.class),
450+
new Pair<Integer, Class>(ErrorCodes.ELEMENT_NOT_SELECTABLE, ElementNotSelectableException.class),
451+
new Pair<Integer, Class>(ErrorCodes.JAVASCRIPT_ERROR, WebDriverException.class),
452+
new Pair<Integer, Class>(ErrorCodes.XPATH_LOOKUP_ERROR, InvalidSelectorException.class),
453+
new Pair<Integer, Class>(ErrorCodes.TIMEOUT, TimeoutException.class),
454+
new Pair<Integer, Class>(ErrorCodes.NO_SUCH_WINDOW, NoSuchWindowException.class),
455+
new Pair<Integer, Class>(ErrorCodes.INVALID_COOKIE_DOMAIN, InvalidCookieDomainException.class),
456+
new Pair<Integer, Class>(ErrorCodes.UNABLE_TO_SET_COOKIE, UnableToSetCookieException.class),
457+
new Pair<Integer, Class>(ErrorCodes.UNEXPECTED_ALERT_PRESENT, UnhandledAlertException.class),
458+
new Pair<Integer, Class>(ErrorCodes.NO_ALERT_PRESENT, NoAlertPresentException.class),
459+
new Pair<Integer, Class>(ErrorCodes.ASYNC_SCRIPT_TIMEOUT, ScriptTimeoutException.class),
460+
new Pair<Integer, Class>(ErrorCodes.INVALID_ELEMENT_COORDINATES, InvalidCoordinatesException.class),
461+
new Pair<Integer, Class>(ErrorCodes.IME_NOT_AVAILABLE, ImeNotAvailableException.class),
462+
new Pair<Integer, Class>(ErrorCodes.IME_ENGINE_ACTIVATION_FAILED, ImeActivationFailedException.class),
463+
new Pair<Integer, Class>(ErrorCodes.INVALID_SELECTOR_ERROR, InvalidSelectorException.class),
464+
new Pair<Integer, Class>(ErrorCodes.SESSION_NOT_CREATED, SessionNotCreatedException.class),
465+
new Pair<Integer, Class>(ErrorCodes.MOVE_TARGET_OUT_OF_BOUNDS, MoveTargetOutOfBoundsException.class),
466+
new Pair<Integer, Class>(ErrorCodes.INVALID_XPATH_SELECTOR, InvalidSelectorException.class),
467+
new Pair<Integer, Class>(ErrorCodes.INVALID_XPATH_SELECTOR_RETURN_TYPER, InvalidSelectorException.class)
468468
);
469469

470470
for (Pair<Integer, Class> exception : exceptions) {

0 commit comments

Comments
 (0)