playwright-fluent
Version:
Fluent API around playwright
78 lines (77 loc) • 3.15 kB
JavaScript
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");
describe('record page dialogs', () => {
let browser = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
beforeEach(() => { });
afterEach(async () => {
if (browser) {
await browser.close();
}
});
test('should record 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;
};
// When
await SUT.recordPageDialogs(page, callback);
await page.goto(`file:${path.join(__dirname, 'record-page-dialogs-confirm.test.html')}`);
await (0, utils_1.sleep)(3000);
// Then
expect(dialogIsOpened).toBe(true);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(openedDialog.type()).toBe('confirm');
});
test('should record 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;
};
// When
await SUT.recordPageDialogs(page, callback);
await page.goto(`file:${path.join(__dirname, 'record-page-dialogs-alert.test.html')}`);
await (0, utils_1.sleep)(3000);
// Then
expect(dialogIsOpened).toBe(true);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(openedDialog.type()).toBe('alert');
});
test('should record 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;
};
// When
await SUT.recordPageDialogs(page, callback);
await page.goto(`file:${path.join(__dirname, 'record-page-dialogs-prompt.test.html')}`);
await (0, utils_1.sleep)(3000);
// Then
expect(dialogIsOpened).toBe(true);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(openedDialog.type()).toBe('prompt');
});
});
;