Skip to content

Commit 0b9d599

Browse files
committed
[js] Add support for the alert credentials
1 parent 9da7301 commit 0b9d599

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

javascript/node/selenium-webdriver/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
The top-level `error` module will be removed in v3.0.
2222
* Moved `until.Condition` and `until.WebElementCondition` to the webdriver
2323
module to break a circular dependency.
24+
* Added support for setting the username and password in basic auth pop-up
25+
dialogs (currently IE only).
2426
* FIXED: `io.findInPath()` will no longer match against directories that have
2527
the same basename as the target file.
2628
* FIXED: `phantomjs.Driver` now takes a third argument that defines the path to

javascript/node/selenium-webdriver/http/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ const COMMAND_MAP = new Map([
189189
[cmd.Name.DISMISS_ALERT, post('/session/:sessionId/dismiss_alert')],
190190
[cmd.Name.GET_ALERT_TEXT, get('/session/:sessionId/alert_text')],
191191
[cmd.Name.SET_ALERT_TEXT, post('/session/:sessionId/alert_text')],
192+
[cmd.Name.SET_ALERT_CREDENTIALS, post('/session/:sessionId/alert/credentials')],
192193
[cmd.Name.GET_LOG, post('/session/:sessionId/log')],
193194
[cmd.Name.GET_AVAILABLE_LOG_TYPES, get('/session/:sessionId/log/types')],
194195
[cmd.Name.GET_SESSION_LOGS, post('/logs')],

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ const Name = {
159159
DISMISS_ALERT: 'dismissAlert',
160160
GET_ALERT_TEXT: 'getAlertText',
161161
SET_ALERT_TEXT: 'setAlertValue',
162+
SET_ALERT_CREDENTIALS: 'setAlertCredentials',
162163

163164
EXECUTE_SQL: 'executeSQL',
164165
GET_LOCATION: 'getLocation',

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,6 +2253,23 @@ class Alert {
22532253
return this.text_;
22542254
}
22552255

2256+
/**
2257+
* Sets the username and password in an alert prompting for credentials (such
2258+
* as a Basic HTTP Auth prompt). This method will implicitly
2259+
* {@linkplain #accept() submit} the dialog.
2260+
*
2261+
* @param {string} username The username to send.
2262+
* @param {string} password The password to send.
2263+
* @return {!promise.Promise<void>} A promise that will be resolved when this
2264+
* command has completed.
2265+
*/
2266+
authenticateAs(username, password) {
2267+
return this.driver_.schedule(
2268+
new command.Command(command.Name.SET_ALERT_CREDENTIALS),
2269+
'WebDriver.switchTo().alert()'
2270+
+ `.authenticateAs("${username}", "${password}")`);
2271+
}
2272+
22562273
/**
22572274
* Accepts this alert.
22582275
*
@@ -2347,6 +2364,16 @@ class AlertPromise extends Alert {
23472364
});
23482365
};
23492366

2367+
/**
2368+
* Defers action until the alert has been located.
2369+
* @override
2370+
*/
2371+
this.authenticateAs = function(username, password) {
2372+
return alert.then(function(alert) {
2373+
return alert.authenticateAs(username, password);
2374+
});
2375+
};
2376+
23502377
/**
23512378
* Defers action until the alert has been located.
23522379
* @override

0 commit comments

Comments
 (0)