UNPKG

playwright-fluent

Version:
77 lines (76 loc) 3.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path = tslib_1.__importStar(require("path")); const playwright_1 = require("playwright"); const SUT = tslib_1.__importStar(require("../index")); const record_page_dialogs_1 = require("../../record-page-dialogs"); describe('wait for page dialog to open', () => { // eslint-disable-next-line @typescript-eslint/no-empty-function beforeEach(() => { }); // eslint-disable-next-line @typescript-eslint/no-empty-function afterEach(async () => { }); test('should wait for confirm dialog to open', async () => { // Given const browser = await playwright_1.chromium.launch({ headless: true }); const context = await browser.newContext({ viewport: null }); const page = await context.newPage(); let dialogIsOpened = false; let openedDialog = undefined; const callback = (dialog) => { dialogIsOpened = true; openedDialog = dialog; }; await (0, record_page_dialogs_1.recordPageDialogs)(page, callback); // When await page.goto(`file:${path.join(__dirname, 'wait-for-dialog-confirm.test.html')}`); await SUT.waitForDialog(() => openedDialog, page); // Then expect(dialogIsOpened).toBe(true); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(openedDialog.type()).toBe('confirm'); await browser.close(); }); test('should wait for alert dialog to open', async () => { // Given const browser = await playwright_1.chromium.launch({ headless: true }); const context = await browser.newContext({ viewport: null }); const page = await context.newPage(); let dialogIsOpened = false; let openedDialog = undefined; const callback = (dialog) => { dialogIsOpened = true; openedDialog = dialog; }; await (0, record_page_dialogs_1.recordPageDialogs)(page, callback); // When await page.goto(`file:${path.join(__dirname, 'wait-for-dialog-alert.test.html')}`); await SUT.waitForDialog(() => openedDialog, page); // Then expect(dialogIsOpened).toBe(true); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(openedDialog.type()).toBe('alert'); await browser.close(); }); test('should wait for prompt dialog to open', async () => { // Given const browser = await playwright_1.chromium.launch({ headless: true }); const context = await browser.newContext({ viewport: null }); const page = await context.newPage(); let dialogIsOpened = false; let openedDialog = undefined; const callback = (dialog) => { dialogIsOpened = true; openedDialog = dialog; }; await (0, record_page_dialogs_1.recordPageDialogs)(page, callback); // When await page.goto(`file:${path.join(__dirname, 'wait-for-dialog-prompt.test.html')}`); await SUT.waitForDialog(() => openedDialog, page); // Then expect(dialogIsOpened).toBe(true); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(openedDialog.type()).toBe('prompt'); await browser.close(); }); });