Skip to content

Commit f9d9671

Browse files
JohanLorenzojleyba
authored andcommitted
[js] until.alertIsPresent(): Workaround for GeckoDriver conversion error (#2137)
* [js] until.alertIsPresent(): Workaround for GeckoDriver conversion error * Narrow down check on WebDriverError * Add tests * Updated CHANGES.md
1 parent c8534a6 commit f9d9671

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

javascript/node/selenium-webdriver/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
`builder.Builder#usingHttpAgent()`
55
* Added new wait conditions: `until.urlIs()`, `until.urlContains()`,
66
`until.urlMatches()`
7+
* Added work around for [GeckoDriver bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1274924) raising a type conversion error
78

89
## v2.53.2
910

javascript/node/selenium-webdriver/lib/until.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ exports.ableToSwitchToFrame = function ableToSwitchToFrame(frame) {
115115
exports.alertIsPresent = function alertIsPresent() {
116116
return new Condition('for alert to be present', function(driver) {
117117
return driver.switchTo().alert().catch(function(e) {
118-
if (!(e instanceof error.NoSuchAlertError)) {
118+
if (!(e instanceof error.NoSuchAlertError
119+
// XXX: Workaround for GeckoDriver error `TypeError: can't convert null
120+
// to object`. For more details, see
121+
// https://github.com/SeleniumHQ/selenium/pull/2137
122+
|| (e instanceof error.WebDriverError
123+
&& e.message === `can't convert null to object`)
124+
)) {
119125
throw e;
120126
}
121127
});

javascript/node/selenium-webdriver/test/lib/until_test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,40 @@ describe('until', function() {
145145
return alert.dismiss();
146146
});
147147
});
148+
149+
// TODO: Remove once GeckoDriver doesn't throw this unwanted error.
150+
// See https://github.com/SeleniumHQ/selenium/pull/2137
151+
describe('workaround for GeckoDriver', function() {
152+
it('doesNotFailWhenCannotConvertNullToObject', function() {
153+
var count = 0;
154+
executor.on(CommandName.GET_ALERT_TEXT, function() {
155+
if (count++ < 3) {
156+
throw new error.WebDriverError(`can't convert null to object`);
157+
} else {
158+
return true;
159+
}
160+
}).on(CommandName.DISMISS_ALERT, () => true);
161+
162+
return driver.wait(until.alertIsPresent(), 1000).then(function(alert) {
163+
assert.equal(count, 4);
164+
return alert.dismiss();
165+
});
166+
});
167+
168+
it('keepsRaisingRegularWebdriverError', function() {
169+
var webDriverError = new error.WebDriverError;
170+
171+
executor.on(CommandName.GET_ALERT_TEXT, function() {
172+
throw webDriverError;
173+
});
174+
175+
return driver.wait(until.alertIsPresent(), 1000).then(function() {
176+
throw new Error('driver did not fail against WebDriverError');
177+
}, function(error) {
178+
assert.equal(error, webDriverError);
179+
});
180+
})
181+
});
148182
});
149183

150184
it('testUntilTitleIs', function() {

0 commit comments

Comments
 (0)