UNPKG

playwright-fluent

Version:
88 lines (87 loc) 3.57 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 - find', () => { 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, 'find.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .navigateTo(url); // When const selector = p.selector('[role="row"]').find('foobar'); const handles = await selector.getAllHandles(); const firstHandle = await selector.getFirstHandleOrNull(); // 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, 'find.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .navigateTo(url); // When // prettier-ignore const selector = p .selector('[role="row"]') .find('td') .find('select[data-test-id="my-select"]'); const handles = await selector.getAllHandles(); const firstHandle = await selector.getFirstHandleOrNull(); // Then expect(Array.isArray(handles)).toBe(true); expect(handles.length).toBe(3); expect(await handles[0].evaluate((node) => node.value)).toBe('1'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(await firstHandle.evaluate((node) => node.value)).toBe('1'); expect(await handles[1].evaluate((node) => node.value)).toBe('2'); expect(await handles[2].evaluate((node) => node.value)).toBe('3'); expect(selector.toString()).toBe(`selector([role="row"]) .find(td) .find(select[data-test-id="my-select"])`); }); 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') .find('select[data-test-id="my-select"]'); const url = `file:${path.join(__dirname, 'find.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .navigateTo(url); // When const handles = await selector.getAllHandles(); const firstHandle = await selector.getFirstHandleOrNull(); // Then expect(Array.isArray(handles)).toBe(true); expect(handles.length).toBe(3); expect(await handles[0].evaluate((node) => node.value)).toBe('1'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(await firstHandle.evaluate((node) => node.value)).toBe('1'); expect(await handles[1].evaluate((node) => node.value)).toBe('2'); expect(await handles[2].evaluate((node) => node.value)).toBe('3'); expect(selector.toString()).toBe(`selector([role="row"]) .find(td) .find(select[data-test-id="my-select"])`); }); });