playwright-fluent
Version:
Fluent API around playwright
90 lines (89 loc) • 3.08 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 - acceptDialog()', () => {
let p;
beforeEach(() => {
p = new playwright_fluent_1.PlaywrightFluent();
});
afterEach(async () => {
await p.close();
});
test('should accept dialog alert - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'accept-dialog-alert.test.html')}`;
// When
await p
.withBrowser(browser)
.withOptions({ headless: false })
.WithDialogs()
.navigateTo(url)
.waitForDialog()
.expectThatDialog()
.isOfType('alert')
.acceptDialog();
// Then
expect(p.isDialogOpened()).toBe(false);
expect(p.isDialogClosed()).toBe(true);
});
test('should accept dialog confirm - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'accept-dialog-confirm.test.html')}`;
// When
await p
.withBrowser(browser)
.withOptions({ headless: false })
.WithDialogs()
.navigateTo(url)
.waitForDialog()
.expectThatDialog()
.isOfType('confirm')
.acceptDialog();
// Then
expect(p.isDialogOpened()).toBe(false);
expect(p.isDialogClosed()).toBe(true);
});
test('should accept dialog prompt - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'accept-dialog-prompt.test.html')}`;
// When
await p
.withBrowser(browser)
.withOptions({ headless: false })
.WithDialogs()
.navigateTo(url)
.waitForDialog()
.expectThatDialog()
.isOfType('prompt')
.acceptDialog();
// Then
expect(p.isDialogOpened()).toBe(false);
expect(p.isDialogClosed()).toBe(true);
});
test('should assert that no dialog has been opened - chromium', async () => {
// Given
const browser = 'chromium';
const url = `file:${path_1.default.join(__dirname, 'accept-dialog-prompt.test.html')}`;
// When
let result = undefined;
try {
await p
.withBrowser(browser)
.withOptions({ headless: false })
//.WithDialogs() => be sure that no dialog opens
.navigateTo(url)
// Then
.acceptDialog();
}
catch (error) {
result = error;
}
// Then
expect(result && result.message).toContain('Cannot accept dialog because no dialog has been opened');
});
});
;