UNPKG

playwright-fluent

Version:
127 lines (126 loc) 5.09 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('accept page dialog', () => { let browser = undefined; // eslint-disable-next-line @typescript-eslint/no-empty-function beforeEach(() => { }); afterEach(async () => { if (browser) { await browser.close(); } }); test('should accept 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 onAccepted = () => { dialogIsOpened = false; }; await (0, record_page_dialogs_1.recordPageDialogs)(page, callback); // When await page.goto(`file:${path.join(__dirname, 'accept-dialog-confirm.test.html')}`); await (0, utils_1.sleep)(3000); // Then expect(dialogIsOpened).toBe(true); // When await SUT.acceptDialog(openedDialog, undefined, page, onAccepted); // Then expect(dialogIsOpened).toBe(false); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(openedDialog.type()).toBe('confirm'); }); test('should accept 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 onAccepted = () => { dialogIsOpened = false; }; await (0, record_page_dialogs_1.recordPageDialogs)(page, callback); // When await page.goto(`file:${path.join(__dirname, 'accept-dialog-alert.test.html')}`); await (0, utils_1.sleep)(3000); // Then expect(dialogIsOpened).toBe(true); // When await SUT.acceptDialog(openedDialog, undefined, page, onAccepted); // Then expect(dialogIsOpened).toBe(false); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(openedDialog.type()).toBe('alert'); }); test('should accept 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 onAccepted = () => { dialogIsOpened = false; }; await (0, record_page_dialogs_1.recordPageDialogs)(page, callback); // When await page.goto(`file:${path.join(__dirname, 'accept-dialog-prompt.test.html')}`); await (0, utils_1.sleep)(3000); // Then expect(dialogIsOpened).toBe(true); // When await SUT.acceptDialog(openedDialog, undefined, page, onAccepted); // Then expect(dialogIsOpened).toBe(false); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(openedDialog.type()).toBe('prompt'); }); test('should accept prompt dialog with prompt text', 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 onAccepted = () => { dialogIsOpened = false; }; await (0, record_page_dialogs_1.recordPageDialogs)(page, callback); // When await page.goto(`file:${path.join(__dirname, 'accept-dialog-prompt.test.html')}`); await (0, utils_1.sleep)(3000); // Then expect(dialogIsOpened).toBe(true); // When await SUT.acceptDialog(openedDialog, 'foobar', page, onAccepted); // Then expect(dialogIsOpened).toBe(false); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(openedDialog.type()).toBe('prompt'); }); });