UNPKG

playwright-fluent

Version:
175 lines (174 loc) 6.83 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 placeholder', () => { let p; beforeEach(() => { p = new SUT.PlaywrightFluent(); }); afterEach(async () => { await p.close(); }); test('should throw on a non existing selector - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-placeholder.test.html')}`; const selector = 'foobar'; // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasPlaceholder('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-placeholder.test.html')}`; const selector = p.selector('foobar'); // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasPlaceholder('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 has no placeholder - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-placeholder.test.html')}`; const selector = '#input-with-no-placeholder'; // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasPlaceholder('yo', { timeoutInMilliseconds: 2000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain("Selector '#input-with-no-placeholder' does not have placeholder 'yo', because no placeholder has been found on the selector"); }); test('should throw when selector object has no placeholder - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-placeholder.test.html')}`; const selector = p.selector('input').withValue('input with no placeholder'); // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasPlaceholder('yo', { timeoutInMilliseconds: 2000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain(`'selector(input) .withValue(input with no placeholder)' does not have placeholder 'yo', because no placeholder has been found on the selector`); }); test('should throw when selector does not have the placeholder - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-placeholder.test.html')}`; const selector = '#input-with-placeholder'; // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasPlaceholder('yo', { timeoutInMilliseconds: 2000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain("Selector '#input-with-placeholder' does not have placeholder 'yo', but instead has placeholder 'enter text here'"); }); test('should throw when selector object does have the placeholder - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-placeholder.test.html')}`; const selector = p.selector('input').withValue('input with placeholder'); // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .expectThatSelector(selector) .hasPlaceholder('yo', { timeoutInMilliseconds: 2000 }); } catch (error) { result = error; } // Then expect(result && result.message).toContain(`'selector(input) .withValue(input with placeholder)' does not have placeholder 'yo', but instead has placeholder 'enter text here'`); }); test('should wait until selector has expected placeholder - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-placeholder.test.html')}`; const selector = '#dynamically-added-input'; // When await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .hover(selector) .expectThatSelector(selector) .hasPlaceholder('foobar'); // THEN }); test('should wait until selector object has expected placeholder - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'expect-has-placeholder.test.html')}`; const selector = p.selector('input').withValue('dynamically added input'); // When await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .hover(selector) .expectThatSelector(selector) .hasPlaceholder('foobar'); // THEN const placeholder = await selector.placeholder(); expect(placeholder).toBe('foobar'); }); });