UNPKG

playwright-fluent

Version:
87 lines (86 loc) 3.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path = tslib_1.__importStar(require("path")); const fluent_api_1 = require("../../../fluent-api"); describe('Selector API - withExactText', () => { let p; beforeEach(() => { p = new fluent_api_1.PlaywrightFluent(); }); afterEach(async () => { await p.close(); }); test('should get no handle on wrong selector', async () => { // Given const url = `file:${path.join(__dirname, 'with-exact-text.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .navigateTo(url); // When const selector = p.selector('[role="row"]').find('foobar').withExactText('yo'); const handles = await selector.getAllHandles(); const firstHandle = await selector.getHandle(); // Then expect(Array.isArray(handles)).toBe(true); expect(handles.length).toBe(0); expect(firstHandle).toBeNull(); }); test('should get handles', async () => { // Given const url = `file:${path.join(__dirname, 'with-exact-text.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .navigateTo(url); // When // prettier-ignore const selector = p .selector('[role="row"]') .find('td') .withExactText('cell'); const handles = await selector.getAllHandles(); const firstHandle = await selector.getHandle(); // Then expect(Array.isArray(handles)).toBe(true); expect(handles.length).toBe(2); expect(await handles[0].evaluate((node) => node.innerText)).toBe('cell'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(await firstHandle.evaluate((node) => node.innerText)).toBe('cell'); expect(await handles[1].evaluate((node) => node.innerText)).toBe('cell'); expect(selector.toString()).toBe(`selector([role="row"]) .find(td) .withExactText(cell)`); }); test('should get handles, even when selector is created before browser is launched', async () => { // Given // prettier-ignore const selector = p.selector('[role="row"]') .find('td') .withExactText('cell'); const url = `file:${path.join(__dirname, 'with-exact-text.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .navigateTo(url) .expectThat(selector) .exists(); // When const handles = await selector.getAllHandles(); const firstHandle = await selector.getHandle(); // Then expect(Array.isArray(handles)).toBe(true); expect(handles.length).toBe(2); expect(await handles[0].evaluate((node) => node.innerText)).toBe('cell'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(await firstHandle.evaluate((node) => node.innerText)).toBe('cell'); expect(await handles[1].evaluate((node) => node.innerText)).toBe('cell'); expect(selector.toString()).toBe(`selector([role="row"]) .find(td) .withExactText(cell)`); }); });