UNPKG

playwright-fluent

Version:
103 lines (102 loc) 4.06 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 utils_1 = require("../../../../utils"); const record_page_dialogs_1 = require("../../record-page-dialogs"); describe('cancel page dialog', () => { let browser = undefined; // eslint-disable-next-line @typescript-eslint/no-empty-function beforeEach(() => { }); afterEach(async () => { if (browser) { await browser.close(); } }); test('should cancel confirm dialog', async () => { // Given 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; }; const onCanceled = () => { dialogIsOpened = false; }; await (0, record_page_dialogs_1.recordPageDialogs)(page, callback); // When await page.goto(`file:${path.join(__dirname, 'cancel-dialog-confirm.test.html')}`); await (0, utils_1.sleep)(3000); // Then expect(dialogIsOpened).toBe(true); // When await SUT.cancelDialog(openedDialog, page, onCanceled); await (0, utils_1.sleep)(3000); // Then expect(dialogIsOpened).toBe(false); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(openedDialog.type()).toBe('confirm'); }); test('should cancel alert dialog', async () => { // Given 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; }; const onCanceled = () => { dialogIsOpened = false; }; await (0, record_page_dialogs_1.recordPageDialogs)(page, callback); // When await page.goto(`file:${path.join(__dirname, 'cancel-dialog-alert.test.html')}`); await (0, utils_1.sleep)(3000); // Then expect(dialogIsOpened).toBe(true); // When await SUT.cancelDialog(openedDialog, page, onCanceled); await (0, utils_1.sleep)(3000); // Then expect(dialogIsOpened).toBe(false); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(openedDialog.type()).toBe('alert'); }); test('should cancel prompt dialog', async () => { // Given 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; }; const onCanceled = () => { dialogIsOpened = false; }; await (0, record_page_dialogs_1.recordPageDialogs)(page, callback); // When await page.goto(`file:${path.join(__dirname, 'cancel-dialog-prompt.test.html')}`); await (0, utils_1.sleep)(3000); // Then expect(dialogIsOpened).toBe(true); // When await SUT.cancelDialog(openedDialog, page, onCanceled); await (0, utils_1.sleep)(3000); // Then expect(dialogIsOpened).toBe(false); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(openedDialog.type()).toBe('prompt'); }); });