appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
78 lines • 2.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAlertText = getAlertText;
exports.setAlertText = setAlertText;
exports.postAcceptAlert = postAcceptAlert;
exports.postDismissAlert = postDismissAlert;
exports.getAlertButtons = getAlertButtons;
exports.mobileHandleAlert = mobileHandleAlert;
/**
* Gets the text of the currently displayed alert.
*
* @returns The alert text, or null if no alert is displayed
*/
async function getAlertText() {
return await this.proxyCommand('/alert/text', 'GET');
}
/**
* Sets the text in an alert input field.
*
* @param value - The text to set
*/
async function setAlertText(value) {
await this.proxyCommand('/alert/text', 'POST', { value });
}
/**
* Accepts the currently displayed alert.
*
* @param opts - Options including optional button label
*/
async function postAcceptAlert(opts = {}) {
await this.proxyCommand('/alert/accept', 'POST', toAlertParams(opts));
}
/**
* Dismisses the currently displayed alert.
*
* @param opts - Options including optional button label
*/
async function postDismissAlert(opts = {}) {
await this.proxyCommand('/alert/dismiss', 'POST', toAlertParams(opts));
}
/**
* Gets the list of button labels from the currently displayed alert.
*
* @returns The list of button labels
* @internal
*/
async function getAlertButtons() {
return await this.proxyCommand('/wda/alert/buttons', 'GET');
}
/**
* Tries to apply the given action to the currently visible alert.
*
* @param action - The actual action to apply
* @param buttonLabel - The name of the button used to perform the chosen alert action. Only makes sense if the action is `accept` or `dismiss`
* @returns If `action` is `getButtons`, a list of alert button labels; otherwise nothing
* @remarks This should really be separate commands.
*/
async function mobileHandleAlert(action, buttonLabel) {
switch (action) {
case 'accept':
return await this.postAcceptAlert({ buttonLabel });
case 'dismiss':
return await this.postDismissAlert({ buttonLabel });
case 'getButtons':
return await this.getAlertButtons();
default:
throw new Error(`The 'action' value should be either 'accept', 'dismiss' or 'getButtons'. ` +
`'${action}' is provided instead.`);
}
}
function toAlertParams(opts = {}) {
const params = {};
if (opts.buttonLabel) {
params.name = opts.buttonLabel;
}
return params;
}
//# sourceMappingURL=alert.js.map