playwright-fluent
Version:
Fluent API around playwright
96 lines (95 loc) • 3.66 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const path_1 = tslib_1.__importDefault(require("path"));
const playwright_fluent_1 = require("../../playwright-fluent");
describe('Playwright Fluent - waitForDialog()', () => {
let p;
beforeEach(() => {
p = new playwright_fluent_1.PlaywrightFluent();
});
afterEach(async () => {
await p.close();
});
test('should wait for dialog alert - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'wait-for-dialog-alert.test.html')}`;
// When
await p
.withBrowser(browser)
.withOptions({ headless: false })
.WithDialogs()
.navigateTo(url)
.waitForDialog()
// Then
.expectThatDialog()
.isOfType('alert', { timeoutInMilliseconds: 0 });
});
test('should wait for dialog confirm - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'wait-for-dialog-confirm.test.html')}`;
// When
await p
.withBrowser(browser)
.withOptions({ headless: false })
.WithDialogs()
.navigateTo(url)
.waitForDialog()
// Then
.expectThatDialog()
.isOfType('confirm', { timeoutInMilliseconds: 0 });
});
test('should wait for dialog prompt - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'wait-for-dialog-prompt.test.html')}`;
// When
await p
.withBrowser(browser)
.withOptions({ headless: false })
.WithDialogs()
.navigateTo(url)
.waitForDialog()
// Then
.expectThatDialog()
.isOfType('prompt', { timeoutInMilliseconds: 0 });
});
test('should assert that no subscription to page dialog events has been done - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'wait-for-dialog-prompt.test.html')}`;
// When
let result = undefined;
try {
await p
.withBrowser(browser)
.withOptions({ headless: false })
//.WithDialogs() => withDialogs() is mandatory to use expectThatDialog()
.navigateTo(url)
// Then
.waitForDialog({ timeoutInMilliseconds: 1000 });
}
catch (error) {
result = error;
}
// Then
expect(result && result.message).toContain("No dialog has been opened. Maybe you forgot to call the '.withDialogs()' on the playwright-fluent instance.");
});
test('should wait for dialog prompt without throwing - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'wait-for-dialog-prompt.test.html')}`;
// When
await p
.withBrowser(browser)
.withOptions({ headless: false })
// .WithDialogs() => no dialog will be opened because no subscription to page dialog events has been done
.navigateTo(url)
.waitForDialog({ timeoutInMilliseconds: 1000, throwOnTimeout: false });
// Then
expect(p.isDialogOpened()).toBe(false);
expect(p.isDialogClosed()).toBe(true);
});
});
;