UNPKG

playwright-fluent

Version:
68 lines (67 loc) 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path = tslib_1.__importStar(require("path")); const SUT = tslib_1.__importStar(require("../../playwright-fluent")); describe('Playwright Fluent - expect func resolves to', () => { let p; beforeEach(() => { p = new SUT.PlaywrightFluent(); }); afterEach(async () => { await p.close(); }); test('should wait until selector value has expected value - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-resolves-to.test.html')}`; const selector = p.selector('input').withValue('dynamically added'); // When // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url); // Then await p.expectThatAsyncFunc(() => selector.value()).resolvesTo('I am dynamically added in DOM'); }); test('should wait until selector count is expected - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-resolves-to.test.html')}`; // prettier-ignore const selector = p .selector('[role="row"]') .find('td') .find('p'); // When // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url); // Then await p.expectThatAsyncFunc(() => selector.count()).resolvesTo(6); }); test('should give back an error when selector does not resolve to expected value', async () => { // Given const url = `file:${path.join(__dirname, 'expect-resolves-to.test.html')}`; const selector = p.selector('foobar'); // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatAsyncFunc(() => selector.count()) .resolvesTo(1, { timeoutInMilliseconds: 1000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain("Async function did not have expected result '1', but instead it resolved to '0'"); }); });