UNPKG

playwright-fluent

Version:
141 lines (140 loc) 5.07 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 - clearText', () => { let p; beforeEach(() => { p = new SUT.PlaywrightFluent(); }); afterEach(async () => { await p.close(); }); test('should first click on an element - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'clear-text.test.html')}`; // const selector = 'foobar'; // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .clearText(); } catch (error) { result = error; } // Then expect(result && result.message).toContain('You must first click on an editable element before clearing text'); }); test('should first click on an editable element - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'clear-text.test.html')}`; const selector = '#not-editable-content'; // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .click(selector) .clearText(); } catch (error) { result = error; } // Then expect(result && result.message).toContain('You must first click on an editable element before clearing text'); }); test('should raise an error when clicked div is not editable - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'clear-text.test.html')}`; const selector = '#content-not-editable-div'; // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .click(selector) .clearText(); } catch (error) { result = error; } // Then expect(result && result.message).toContain('You must first click on an editable element before clearing text'); }); test('should clear text in an input selector - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'clear-text.test.html')}`; const selector = '#in-view-port'; // When await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .click(selector) .clearText(); // Then const currentValue = await p.getValueOf(selector); expect(currentValue).toBe(''); }); test('should clear text in an input selector object - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'clear-text.test.html')}`; const selector = p.selector('input').withValue('I am in viewport'); // When await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .click(selector) .clear(); // use alias instead of clearText() // Then const currentValue = await p.getValueOf('#in-view-port'); expect(currentValue).toBe(''); }); test('should clear text in a contenteditable selector object - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'clear-text.test.html')}`; const selector = p.selector('p').withText('dynamically added'); // When await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .click(selector) .clearText(); // Then const currentText = await p.getInnerTextOf('p#dynamically-added'); expect(currentText).toBe(''); }); test('should clear text in a contenteditable div selector object - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'clear-text.test.html')}`; const selector = p.selector('div[contenteditable="true"]').withText('editable div'); // When await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .click(selector) .clearText(); // Then const currentText = await p.getInnerTextOf('div#content-editable-div'); expect(currentText).toBe(''); }); });