@qavajs/steps-wdio
Version:
qavajs steps to interact with webdriverio
110 lines • 3.4 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@qavajs/core");
class DialogHolder {
constructor() {
this.isListening = false;
}
}
const dialogHolder = new DialogHolder();
function checkIfListening(isListening) {
if (!isListening) {
throw new Error(`Step 'I will wait for alert/dialog' must be called before`);
}
}
/**
* Start listen for alert
* @example I will wait for dialog
*/
(0, core_1.When)('I will wait for alert/dialog', async function () {
if (this.wdio.browser.isBidi) {
dialogHolder.isListening = true;
dialogHolder.currentDialog = new Promise(resolve => this.wdio.browser.on('dialog', resolve));
}
});
/**
* Accept alert
* @example I accept alert
*/
(0, core_1.When)('I accept alert/dialog', async function () {
if (this.wdio.browser.isBidi) {
checkIfListening(dialogHolder.isListening);
const dialog = await dialogHolder.currentDialog;
await dialog.accept();
}
else {
await this.wdio.browser.waitUntil(async () => {
await this.wdio.browser.acceptAlert();
return true;
}, {
timeout: this.config.browser.timeout.present,
interval: 2000
});
}
});
/**
* Dismiss alert
* @example I dismiss alert
*/
(0, core_1.When)('I dismiss alert', async function () {
if (this.wdio.browser.isBidi) {
checkIfListening(dialogHolder.isListening);
const dialog = await dialogHolder.currentDialog;
await dialog.dismiss();
}
else {
await this.wdio.browser.waitUntil(async () => {
await this.wdio.browser.dismissAlert();
return true;
}, {
timeout: this.config.browser.timeout.present,
interval: 2000
});
}
});
/**
* I type {string} to alert
* @example I type 'coffee' to alert
*/
(0, core_1.When)('I type {value} to alert', async function (value) {
const message = await value.value();
if (this.wdio.browser.isBidi) {
checkIfListening(dialogHolder.isListening);
const dialog = await dialogHolder.currentDialog;
await dialog.accept(message);
}
else {
await this.wdio.browser.waitUntil(async () => {
await this.wdio.browser.sendAlertText(message);
await this.wdio.browser.acceptAlert();
return true;
}, {
timeout: this.config.browser.timeout.present,
interval: 2000
});
}
});
/**
* Verify that text of an alert meets expectation
* @param {string} validationType - validation
* @param {string} value - expected text value
* @example I expect text of alert does not contain 'coffee'
*/
(0, core_1.Then)('I expect text of alert {validation} {value}', async function (validation, expected) {
let alertText;
if (this.wdio.browser.isBidi) {
checkIfListening(dialogHolder.isListening);
const dialog = await dialogHolder.currentDialog;
alertText = dialog.message();
}
else {
alertText = await this.wdio.browser.waitUntil(async () => {
return await this.wdio.browser.getAlertText();
}, {
timeout: this.config.browser.timeout.present,
interval: 2000
});
}
validation(alertText, await expected.value());
});
//# sourceMappingURL=dialog.js.map
;