UNPKG

playwright-fluent

Version:
130 lines (129 loc) 4.91 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 has value', () => { let p; beforeEach(() => { p = new SUT.PlaywrightFluent(); }); afterEach(async () => { await p.close(); }); test('should wait until selector has expected value - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-value.test.html')}`; const selector = '#dynamically-added-input'; // When await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .hover(selector); // Then await p.expectThatSelector(selector).hasValue('hovered'); }); test('should wait until selector object has expected value - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-value.test.html')}`; const selector = p.selector('input').withValue('dynamically added'); // When await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasValue('dynamically added'); // Then const currentValue = await selector.value(); expect(currentValue).toBe('dynamically added input'); }); test('should throw on a non existing selector - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-value.test.html')}`; const selector = 'foobar'; // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasValue('yo', { timeoutInMilliseconds: 2000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain("Selector 'foobar' was not found in DOM."); }); test('should throw on a non existing selector object - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-value.test.html')}`; const selector = p.selector('foobar'); // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasValue('yo', { timeoutInMilliseconds: 2000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain("Selector 'selector(foobar)' was not found in DOM."); }); test('should throw when selector does not contain value - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-value.test.html')}`; const selector = '#dynamically-added-input'; // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasValue('yo', { timeoutInMilliseconds: 4000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain("Value of selector '#dynamically-added-input' does not contain 'yo', but instead it contains 'dynamically added input'"); }); test('should throw when selector object does not contain value - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-value.test.html')}`; const selector = p.selector('input').withValue('dynamically added'); // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasValue('yo', { timeoutInMilliseconds: 4000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain(`Value of 'selector(input) .withValue(dynamically added)' does not contain 'yo', but instead it contains 'dynamically added input'`); }); });