UNPKG

playwright-fluent

Version:
120 lines (119 loc) 4.26 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 - typeText', () => { 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, 'typetext.test.html')}`; // const selector = 'foobar'; // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .typeText('foobar'); } catch (error) { result = error; } // Then expect(result && result.message).toContain('You must first click on an editable element before typing text'); }); test('should first click on an editable element - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'typetext.test.html')}`; const selector = '#not-editable-content'; // When let result = undefined; try { await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .click(selector) .typeText('foobar'); } catch (error) { result = error; } // Then expect(result && result.message).toContain('You must first click on an editable element before typing text'); }); test('should type text in an input selector - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'typetext.test.html')}`; const selector = '#in-view-port'; // When await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .click(selector) .typeText('foobar'); // Then const currentValue = await p.getValueOf(selector); expect(currentValue).toBe('foobar'); }); test('should clear text before typing in an input selector object - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'typetext.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) .typeText('foobar'); // Then const currentValue = await p.getValueOf('#in-view-port'); expect(currentValue).toBe('foobar'); }); test('should type text in an empty input selector object - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'typetext.test.html')}`; const selector = p.selector('input#in-view-port-and-empty'); // When await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .click(selector) .typeText('foobar'); // Then const currentValue = await p.getValueOf('#in-view-port-and-empty'); expect(currentValue).toBe('foobar'); }); test('should type text in an editable selector - chromium', async () => { // Given const url = `file:${path.join(__dirname, 'typetext.test.html')}`; const selector = 'p#editable-content'; // When await p .withBrowser('chromium') .withOptions({ headless: false }) .withCursor() .navigateTo(url) .click(selector) .typeText('foobar'); // Then const currentValue = await p.getInnerTextOf(selector); expect(currentValue).toBe('foobar'); }); });