UNPKG

playwright-fluent

Version:
113 lines (112 loc) 4.02 kB
"use strict"; 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().hasValue(value)', () => { let p; beforeEach(() => { p = new playwright_fluent_1.PlaywrightFluent(); }); afterEach(async () => { await p.close(); }); test('should assert dialog has value - alert - chromium', async () => { // Given const browser = 'chromium'; const url = `file:${path_1.default.join(__dirname, 'expect-dialog-has-value-alert.test.html')}`; // When await p .withBrowser(browser) .withOptions({ headless: true }) .WithDialogs() .navigateTo(url) // Then .expectThatDialog() .isOfType('alert') // And .expectThatDialog() .hasValue(''); }); test('should assert dialog has value - confirm - chromium', async () => { // Given const browser = 'chromium'; const url = `file:${path_1.default.join(__dirname, 'expect-dialog-has-value-confirm.test.html')}`; // When await p .withBrowser(browser) .withOptions({ headless: true }) .WithDialogs() .navigateTo(url) // Then .expectThatDialog() .isOfType('confirm') // And .expectThatDialog() .hasValue(''); }); test('should assert dialog has value - prompt - chromium', async () => { // Given const browser = 'chromium'; const url = `file:${path_1.default.join(__dirname, 'expect-dialog-has-value-prompt.test.html')}`; // When await p .withBrowser(browser) .withOptions({ headless: true }) .WithDialogs() .navigateTo(url) // Then .expectThatDialog() .isOfType('prompt') // And .expectThatDialog() .hasValue('yes'); }); test('should assert wrong value on opened dialog - chromium', async () => { // Given const browser = 'chromium'; const url = `file:${path_1.default.join(__dirname, 'expect-dialog-has-value-prompt.test.html')}`; // When let result = undefined; try { await p .withBrowser(browser) .withOptions({ headless: true }) .WithDialogs() .navigateTo(url) // Then .expectThatDialog() .isOfType('prompt') // And .expectThatDialog() .hasValue('foobar', { timeoutInMilliseconds: 0 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain("Current dialog has value 'yes sure!' but it should be 'foobar'"); }); 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-has-value-prompt.test.html')}`; // When let result = undefined; try { await p .withBrowser(browser) .withOptions({ headless: true }) //.WithDialogs() => no dialog will be opened .navigateTo(url) // Then .expectThatDialog() .hasValue('foobar', { 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."); }); });