Skip to content

Commit

Permalink
[js] until.alertIsPresent(): Workaround for GeckoDriver conversion er…
Browse files Browse the repository at this point in the history
…ror (SeleniumHQ#2137)

* [js] until.alertIsPresent(): Workaround for GeckoDriver conversion error

* Narrow down check on WebDriverError

* Add tests

* Updated CHANGES.md
  • Loading branch information
JohanLorenzo authored and jleyba committed May 23, 2016
1 parent c8534a6 commit f9d9671
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions javascript/node/selenium-webdriver/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
`builder.Builder#usingHttpAgent()`
* Added new wait conditions: `until.urlIs()`, `until.urlContains()`,
`until.urlMatches()`
* Added work around for [GeckoDriver bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1274924) raising a type conversion error

## v2.53.2

Expand Down
8 changes: 7 additions & 1 deletion javascript/node/selenium-webdriver/lib/until.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ exports.ableToSwitchToFrame = function ableToSwitchToFrame(frame) {
exports.alertIsPresent = function alertIsPresent() {
return new Condition('for alert to be present', function(driver) {
return driver.switchTo().alert().catch(function(e) {
if (!(e instanceof error.NoSuchAlertError)) {
if (!(e instanceof error.NoSuchAlertError
// XXX: Workaround for GeckoDriver error `TypeError: can't convert null
// to object`. For more details, see
// https://github.com/SeleniumHQ/selenium/pull/2137
|| (e instanceof error.WebDriverError
&& e.message === `can't convert null to object`)
)) {
throw e;
}
});
Expand Down
34 changes: 34 additions & 0 deletions javascript/node/selenium-webdriver/test/lib/until_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,40 @@ describe('until', function() {
return alert.dismiss();
});
});

// TODO: Remove once GeckoDriver doesn't throw this unwanted error.
// See https://github.com/SeleniumHQ/selenium/pull/2137
describe('workaround for GeckoDriver', function() {
it('doesNotFailWhenCannotConvertNullToObject', function() {
var count = 0;
executor.on(CommandName.GET_ALERT_TEXT, function() {
if (count++ < 3) {
throw new error.WebDriverError(`can't convert null to object`);
} else {
return true;
}
}).on(CommandName.DISMISS_ALERT, () => true);

return driver.wait(until.alertIsPresent(), 1000).then(function(alert) {
assert.equal(count, 4);
return alert.dismiss();
});
});

it('keepsRaisingRegularWebdriverError', function() {
var webDriverError = new error.WebDriverError;

executor.on(CommandName.GET_ALERT_TEXT, function() {
throw webDriverError;
});

return driver.wait(until.alertIsPresent(), 1000).then(function() {
throw new Error('driver did not fail against WebDriverError');
}, function(error) {
assert.equal(error, webDriverError);
});
})
});
});

it('testUntilTitleIs', function() {
Expand Down

0 comments on commit f9d9671

Please sign in to comment.