Skip to content

Commit 70209d1

Browse files
committed
Update issue 7641
Adjust bot.ErrorCode values for alerts to be consistent with the spec.
1 parent 098bedd commit 70209d1

File tree

10 files changed

+29
-19
lines changed

10 files changed

+29
-19
lines changed

javascript/atoms/error.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ bot.ErrorCode = {
4646
NO_SUCH_WINDOW: 23,
4747
INVALID_COOKIE_DOMAIN: 24,
4848
UNABLE_TO_SET_COOKIE: 25,
49+
/** @deprecated */
4950
MODAL_DIALOG_OPENED: 26,
51+
UNEXPECTED_ALERT_OPEN: 26,
52+
NO_SUCH_ALERT: 27,
53+
/** @deprecated */
5054
NO_MODAL_DIALOG_OPEN: 27,
5155
SCRIPT_TIMEOUT: 28,
5256
INVALID_ELEMENT_COORDINATES: 29,
@@ -173,6 +177,7 @@ goog.scope(function() {
173177
map[code.METHOD_NOT_ALLOWED] = state.UNSUPPORTED_OPERATION;
174178
map[code.MOVE_TARGET_OUT_OF_BOUNDS] = state.MOVE_TARGET_OUT_OF_BOUNDS;
175179
map[code.NO_MODAL_DIALOG_OPEN] = state.NO_SUCH_ALERT;
180+
map[code.NO_SUCH_ALERT] = state.NO_SUCH_ALERT;
176181
map[code.NO_SUCH_ELEMENT] = state.NO_SUCH_ELEMENT;
177182
map[code.NO_SUCH_FRAME] = state.NO_SUCH_FRAME;
178183
map[code.NO_SUCH_WINDOW] = state.NO_SUCH_WINDOW;
@@ -183,6 +188,7 @@ goog.scope(function() {
183188
map[code.TIMEOUT] = state.TIMEOUT;
184189
map[code.UNABLE_TO_SET_COOKIE] = state.UNABLE_TO_SET_COOKIE;
185190
map[code.MODAL_DIALOG_OPENED] = state.UNEXPECTED_ALERT_OPEN;
191+
map[code.UNEXPECTED_ALERT_OPEN] = state.UNEXPECTED_ALERT_OPEN
186192
map[code.UNKNOWN_ERROR] = state.UNKNOWN_ERROR;
187193
map[code.UNSUPPORTED_OPERATION] = state.UNKNOWN_COMMAND;
188194
}); // goog.scope

javascript/firefox-driver/js/firefoxDriver.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ FirefoxDriver.prototype.getAlert = function(respond) {
879879
fxdriver.modals.isModalPresent(
880880
function(present) {
881881
if (!present) {
882-
respond.status = bot.ErrorCode.NO_MODAL_DIALOG_OPEN;
882+
respond.status = bot.ErrorCode.NO_SUCH_ALERT;
883883
respond.value = { message: 'No alert is present' };
884884
}
885885
respond.send();
@@ -892,7 +892,7 @@ FirefoxDriver.prototype.dismissAlert = function(respond) {
892892
fxdriver.modals.isModalPresent(
893893
function(present) {
894894
if (!present) {
895-
respond.status = bot.ErrorCode.NO_MODAL_DIALOG_OPEN;
895+
respond.status = bot.ErrorCode.NO_SUCH_ALERT;
896896
respond.value = { message: 'No alert is present' };
897897
} else {
898898
fxdriver.modals.dismissAlert(self);
@@ -906,7 +906,7 @@ FirefoxDriver.prototype.acceptAlert = function(respond) {
906906
fxdriver.modals.isModalPresent(
907907
function(present) {
908908
if (!present) {
909-
respond.status = bot.ErrorCode.NO_MODAL_DIALOG_OPEN;
909+
respond.status = bot.ErrorCode.NO_SUCH_ALERT;
910910
respond.value = { message: 'No alert is present' };
911911
} else {
912912
fxdriver.modals.acceptAlert(self);
@@ -923,7 +923,7 @@ FirefoxDriver.prototype.getAlertText = function(respond) {
923923
if (present) {
924924
respond.value = fxdriver.modals.getText(driver);
925925
} else {
926-
respond.status = bot.ErrorCode.NO_MODAL_DIALOG_OPEN;
926+
respond.status = bot.ErrorCode.NO_SUCH_ALERT;
927927
respond.value = { message: 'No alert is present' };
928928
}
929929
respond.send();
@@ -935,7 +935,7 @@ FirefoxDriver.prototype.setAlertValue = function(respond, parameters) {
935935
fxdriver.modals.isModalPresent(
936936
function(present) {
937937
if (!present) {
938-
respond.status = bot.ErrorCode.NO_MODAL_DIALOG_OPEN;
938+
respond.status = bot.ErrorCode.NO_SUCH_ALERT;
939939
respond.value = { message: 'No alert is present' };
940940
} else {
941941
fxdriver.modals.setValue(parameters['text']);

javascript/firefox-driver/js/modals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ fxdriver.modals.signalOpenModal = function(parent, text) {
179179
} else {
180180
errorMessage += ' The alert disappeared before it could be closed.';
181181
}
182-
res.sendError(new WebDriverError(bot.ErrorCode.MODAL_DIALOG_OPENED,
182+
res.sendError(new WebDriverError(bot.ErrorCode.UNEXPECTED_ALERT_OPEN,
183183
errorMessage, {alert: {text: text}}));
184184
}, 2000);
185185
} else {

javascript/firefox-driver/js/nsCommandProcessor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ nsCommandProcessor.prototype.execute = function(jsonCommandString,
484484
}
485485
fxdriver.logging.error('Sending error from command ' +
486486
command.name + ' with alertText: ' + modalText);
487-
response.sendError(new WebDriverError(bot.ErrorCode.MODAL_DIALOG_OPENED,
487+
response.sendError(new WebDriverError(bot.ErrorCode.UNEXPECTED_ALERT_OPEN,
488488
'Modal dialog present', {alert: {text: modalText}}));
489489
return;
490490
}

javascript/firefox-driver/js/preconditions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fxdriver.preconditions.writable = function(doc, parameters) {
7878
*/
7979
fxdriver.preconditions.noAlertPresent = function(driver) {
8080
if (driver.modalOpen) {
81-
return new WebDriverError(bot.ErrorCode.MODAL_DIALOG_OPENED,
81+
return new WebDriverError(bot.ErrorCode.UNEXPECTED_ALERT_OPEN,
8282
'A modal dialog, such as an alert, is open.');
8383
}
8484
};
@@ -91,7 +91,7 @@ fxdriver.preconditions.noAlertPresent = function(driver) {
9191
*/
9292
fxdriver.preconditions.alertPresent = function(driver) {
9393
if (!driver.modalOpen) {
94-
return new WebDriverError(bot.ErrorCode.NO_MODAL_DIALOG_OPEN,
94+
return new WebDriverError(bot.ErrorCode.NO_SUCH_ALERT,
9595
'A modal dialog, such as an alert, is not open.');
9696
}
9797
};

javascript/node/selenium-webdriver/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
* For consistency with other language bindings, deprecated
99
`UnhandledAlertError#getAlert` and added `#getAlertText`.
1010
`getAlert` will be removed in `2.45.0`.
11+
* FIXED: 7641: Deprecated `ErrorCode.NO_MODAL_DIALOG_OPEN` and
12+
`ErrorCode.MODAL_DIALOG_OPENED` in favor of the new
13+
`ErrorCode.NO_SUCH_ALERT` and `ErrorCode.UNEXPECTED_ALERT_OPEN`,
14+
respecitvely.
1115
* FIXED: 7563: Mocha integration no longer disables timeouts. Default Mocha
1216
timeouts apply (2000 ms) and may be changed using `this.timeout(ms)`.
1317
* FIXED: 7470: Make it easier to create WebDriver instances in custom flows for

javascript/safari-driver/alert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ goog.require('bot.ErrorCode');
2626
*/
2727
safaridriver.alert.createResponse = function(txt) {
2828
return {
29-
'status': bot.ErrorCode.MODAL_DIALOG_OPENED,
29+
'status': bot.ErrorCode.UNEXPECTED_ALERT_OPEN,
3030
'value': {
3131
'message':
3232
'A modal dialog was opened. The SafariDriver does not support ' +

javascript/safari-driver/extension/commands.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ safaridriver.extension.commands.executeAsyncScript = function(session,
488488
* @see http://code.google.com/p/selenium/issues/detail?id=3862
489489
*/
490490
safaridriver.extension.commands.handleNoAlertsPresent = function() {
491-
throw new bot.Error(bot.ErrorCode.NO_MODAL_DIALOG_OPEN,
491+
throw new bot.Error(bot.ErrorCode.NO_SUCH_ALERT,
492492
'The SafariDriver does not support alert handling. To prevent tests ' +
493493
'from handing when an alert is opened, they are always immediately ' +
494494
'dismissed. For more information, see ' +

javascript/webdriver/test/webdriver_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,7 +2101,7 @@ function testInterceptsAndTransformsUnhandledAlertErrors() {
21012101
var testHelper = TestHelper.
21022102
expectingSuccess().
21032103
expect(CName.FIND_ELEMENT, {'using':'id', 'value':'foo'}).
2104-
andReturnError(ECode.MODAL_DIALOG_OPENED, {
2104+
andReturnError(ECode.UNEXPECTED_ALERT_OPEN, {
21052105
'message': 'boom',
21062106
'alert': {'text': 'hello'}
21072107
}).
@@ -2125,7 +2125,7 @@ function testUnhandledAlertErrors_usesEmptyStringIfAlertTextOmittedFromResponse(
21252125
var testHelper = TestHelper.
21262126
expectingSuccess().
21272127
expect(CName.FIND_ELEMENT, {'using':'id', 'value':'foo'}).
2128-
andReturnError(ECode.MODAL_DIALOG_OPENED, {'message': 'boom'}).
2128+
andReturnError(ECode.UNEXPECTED_ALERT_OPEN, {'message': 'boom'}).
21292129
replayAll();
21302130

21312131
var pair = callbackPair(null, function(e) {
@@ -2185,9 +2185,9 @@ function testWebElementsBelongToSameFlowAsParentDriver() {
21852185

21862186
function testSwitchToAlertThatIsNotPresent() {
21872187
var testHelper = TestHelper
2188-
.expectingFailure(expectedError(ECode.NO_MODAL_DIALOG_OPEN, 'no alert'))
2188+
.expectingFailure(expectedError(ECode.NO_SUCH_ALERT, 'no alert'))
21892189
.expect(CName.GET_ALERT_TEXT)
2190-
.andReturnError(ECode.NO_MODAL_DIALOG_OPEN, {'message': 'no alert'})
2190+
.andReturnError(ECode.NO_SUCH_ALERT, {'message': 'no alert'})
21912191
.replayAll();
21922192

21932193
var driver = testHelper.createDriver();

javascript/webdriver/webdriver.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ webdriver.WebDriver.prototype.schedule = function(command, description) {
294294
bot.response.checkResponse(response);
295295
} catch (ex) {
296296
var value = response['value'];
297-
if (ex.code === bot.ErrorCode.MODAL_DIALOG_OPENED) {
297+
if (ex.code === bot.ErrorCode.UNEXPECTED_ALERT_OPEN) {
298298
var text = value && value['alert'] ? value['alert']['text'] : '';
299299
throw new webdriver.UnhandledAlertError(ex.message, text,
300300
new webdriver.Alert(self, text));
@@ -1469,8 +1469,8 @@ webdriver.WebDriver.TargetLocator.prototype.window = function(nameOrHandle) {
14691469

14701470
/**
14711471
* Schedules a command to change focus to the active alert dialog. This command
1472-
* will return a {@link bot.ErrorCode.NO_MODAL_DIALOG_OPEN} error if a modal
1473-
* dialog is not currently open.
1472+
* will return a {@link bot.ErrorCode.NO_SUCH_ALERT} error if an alert dialog
1473+
* is not currently open.
14741474
* @return {!webdriver.AlertPromise} The open alert.
14751475
*/
14761476
webdriver.WebDriver.TargetLocator.prototype.alert = function() {
@@ -2200,7 +2200,7 @@ goog.inherits(webdriver.AlertPromise, webdriver.Alert);
22002200
* @extends {bot.Error}
22012201
*/
22022202
webdriver.UnhandledAlertError = function(message, text, alert) {
2203-
goog.base(this, bot.ErrorCode.MODAL_DIALOG_OPENED, message);
2203+
goog.base(this, bot.ErrorCode.UNEXPECTED_ALERT_OPEN, message);
22042204

22052205
/** @private {string} */
22062206
this.text_ = text;

0 commit comments

Comments
 (0)