UNPKG

@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

48 lines 1.65 kB
import { AbsentModalDialog, AcceptedModalDialog, DismissedModalDialog, ModalDialogHandler } from '@serenity-js/web'; /** * Playwright-specific implementation of [`ModalDialogHandler`](https://serenity-js.org/api/web/class/ModalDialogHandler/). * * @group Models */ export class PlaywrightModalDialogHandler extends ModalDialogHandler { page; defaultHandler = async (dialog) => { await dialog.dismiss(); return new 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 AcceptedModalDialog(dialog.message()); }; } async acceptNextWithValue(text) { this.currentHandler = async (dialog) => { await dialog.accept(String(text)); return new AcceptedModalDialog(dialog.message()); }; } async dismissNext() { this.currentHandler = async (dialog) => { await dialog.dismiss(); return new DismissedModalDialog(dialog.message()); }; } async reset() { this.modalDialog = new AbsentModalDialog(); this.currentHandler = this.defaultHandler; } async discard() { this.page.off('dialog', this.currentHandler); } } //# sourceMappingURL=PlaywrightModalDialogHandler.js.map