@serenity-js/playwright
Version:
Adapter that integrates @serenity-js/web with Playwright, enabling Serenity/JS reporting and using the Screenplay Pattern to write component and end-to-end test scenarios
52 lines • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlaywrightModalDialogHandler = void 0;
const web_1 = require("@serenity-js/web");
/**
* Playwright-specific implementation of [`ModalDialogHandler`](https://serenity-js.org/api/web/class/ModalDialogHandler/).
*
* @group Models
*/
class PlaywrightModalDialogHandler extends web_1.ModalDialogHandler {
page;
defaultHandler = async (dialog) => {
await dialog.dismiss();
return new web_1.DismissedModalDialog(dialog.message());
};
currentHandler;
constructor(page) {
super();
this.page = page;
this.currentHandler = this.defaultHandler;
this.page.on('dialog', async (dialog) => {
this.modalDialog = await this.currentHandler(dialog);
});
}
async acceptNext() {
this.currentHandler = async (dialog) => {
await dialog.accept(dialog.defaultValue());
return new web_1.AcceptedModalDialog(dialog.message());
};
}
async acceptNextWithValue(text) {
this.currentHandler = async (dialog) => {
await dialog.accept(String(text));
return new web_1.AcceptedModalDialog(dialog.message());
};
}
async dismissNext() {
this.currentHandler = async (dialog) => {
await dialog.dismiss();
return new web_1.DismissedModalDialog(dialog.message());
};
}
async reset() {
this.modalDialog = new web_1.AbsentModalDialog();
this.currentHandler = this.defaultHandler;
}
async discard() {
this.page.off('dialog', this.currentHandler);
}
}
exports.PlaywrightModalDialogHandler = PlaywrightModalDialogHandler;
//# sourceMappingURL=PlaywrightModalDialogHandler.js.map