@qavajs/steps-playwright
Version:
qavajs steps to interact with playwright
64 lines • 2.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@qavajs/core");
class DialogHolder {
currentDialog;
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 () {
dialogHolder.isListening = true;
dialogHolder.currentDialog = new Promise(resolve => this.playwright.page.once('dialog', resolve));
});
/**
* Accept alert
* @example I accept alert
*/
(0, core_1.When)('I accept alert/dialog', async function () {
checkIfListening(dialogHolder.isListening);
const dialog = await dialogHolder.currentDialog;
await dialog.accept();
});
/**
* Dismiss alert
* Playwright automatically dismisses all dialogs. This step is just to make it implicitly.
* @example I dismiss alert
*/
(0, core_1.When)('I dismiss alert/dialog', async function () {
checkIfListening(dialogHolder.isListening);
const dialog = await dialogHolder.currentDialog;
await dialog.dismiss();
});
/**
* I type {string} to alert
* @example I type 'coffee' to alert
*/
(0, core_1.When)('I type {value} to alert/dialog', async function (value) {
checkIfListening(dialogHolder.isListening);
const typeValue = await value.value();
const dialog = await dialogHolder.currentDialog;
await dialog.accept(typeValue);
});
/**
* 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/dialog {validation} {value}', async function (validation, expected) {
checkIfListening(dialogHolder.isListening);
const dialog = await dialogHolder.currentDialog;
const message = dialog.message();
const expectedValue = await expected.value();
validation(message, expectedValue);
});
//# sourceMappingURL=dialog.js.map