playwright-fluent
Version:
Fluent API around playwright
124 lines (123 loc) • 4.57 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 - expectThatDialog().isOfType(type)', () => {
let p;
beforeEach(() => {
p = new playwright_fluent_1.PlaywrightFluent();
});
afterEach(async () => {
await p.close();
});
test('should assert dialog is alert - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'expect-dialog-is-of-type-alert.test.html')}`;
// When
await p
.withBrowser(browser)
.withOptions({ headless: false })
.WithDialogs()
.navigateTo(url)
// Then
.expectThatDialog()
.isOfType('alert');
});
test('should assert dialog is confirm - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'expect-dialog-is-of-type-confirm.test.html')}`;
// When
await p
.withBrowser(browser)
.withOptions({ headless: false })
.WithDialogs()
.navigateTo(url)
// Then
.expectThatDialog()
.isOfType('confirm');
});
test('should assert dialog is prompt - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'expect-dialog-is-of-type-prompt.test.html')}`;
// When
await p
.withBrowser(browser)
.withOptions({ headless: false })
.WithDialogs()
.navigateTo(url)
// Then
.expectThatDialog()
.isOfType('prompt');
});
test('should assert unknown type on opened dialog - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'expect-dialog-is-of-type-prompt.test.html')}`;
const unknownDialogType = 'foobar';
// When
let result = undefined;
try {
await p
.withBrowser(browser)
.withOptions({ headless: false })
.WithDialogs()
.navigateTo(url)
// Then
.expectThatDialog()
.isOfType(unknownDialogType, { timeoutInMilliseconds: 1000 });
}
catch (error) {
result = error;
}
// Then
expect(result && result.message).toContain("Unknown dialog type: 'foobar'. It should be 'alert', 'confirm', 'prompt' or 'beforeunload'");
});
test('should assert wrong type on opened dialog - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'expect-dialog-is-of-type-prompt.test.html')}`;
// When
let result = undefined;
try {
await p
.withBrowser(browser)
.withOptions({ headless: false })
.WithDialogs()
.navigateTo(url)
// Then
.expectThatDialog()
.isOfType('alert');
}
catch (error) {
result = error;
}
// Then
expect(result && result.message).toContain("Current dialog is of type 'prompt' but it should be 'alert'");
});
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, 'expect-dialog-is-of-type-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
.expectThatDialog()
.isOfType('prompt', { 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.");
});
});
;