UNPKG

playwright-fluent

Version:
117 lines (116 loc) 4.56 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 - next sibling', () => { 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, 'next-sibling.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .withCursor() .navigateTo(url); // When // prettier-ignore const selector = p .selector('[role="row"]') .withText('foo and bar and baz') .nextSibling(); const handles = await selector.getAllHandles(); // Then expect(Array.isArray(handles)).toBe(true); expect(handles.length).toBe(0); }); test('should get next sibling handle', async () => { // Given const url = `file:${path.join(__dirname, 'next-sibling.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .withCursor() .navigateTo(url); // When // prettier-ignore const selector = p .selector('[role="row"]') .find('select[data-test-id="my-select2"]') .find('option') .nextSibling(); const handles = await selector.getAllHandles(); // Then expect(Array.isArray(handles)).toBe(true); expect(handles.length).toBe(2); expect(await handles[0].evaluate((node) => node.tagName)).toBe('OPTION'); expect(await handles[0].evaluate((node) => node.innerText)).toBe('Select 2 - label 2'); expect(await handles[1].evaluate((node) => node.tagName)).toBe('OPTION'); expect(await handles[1].evaluate((node) => node.innerText)).toBe('Select 2 - label 3'); expect(selector.toString()).toBe(`selector([role="row"]) .find(select[data-test-id="my-select2"]) .find(option) .nextSibling()`); }); test('should get handles, even when selector is created before page is instanciated', async () => { // Given // prettier-ignore const selector = p .selector('[role="row"]') .find('select[data-test-id="my-select2"]') .find('option') .nextSibling(); const url = `file:${path.join(__dirname, 'next-sibling.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .withCursor() .navigateTo(url); // When const handles = await selector.getAllHandles(); // Then expect(Array.isArray(handles)).toBe(true); expect(handles.length).toBe(2); expect(await handles[0].evaluate((node) => node.tagName)).toBe('OPTION'); expect(await handles[0].evaluate((node) => node.innerText)).toBe('Select 2 - label 2'); expect(await handles[1].evaluate((node) => node.tagName)).toBe('OPTION'); expect(await handles[1].evaluate((node) => node.innerText)).toBe('Select 2 - label 3'); expect(selector.toString()).toBe(`selector([role="row"]) .find(select[data-test-id="my-select2"]) .find(option) .nextSibling()`); }); test('should select sibling option', async () => { // Given const url = `file:${path.join(__dirname, 'next-sibling.test.html')}`; const select = 'select[data-test-id="my-select1"]'; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .withCursor() .navigateTo(url) .hover(select); // prettier-ignore const firstOption = p .selector('[role="row"]') .find(select) .find('option'); // When const nextOption = (await firstOption.nextSibling().innerText()) || 'unknown'; await p.select(nextOption).in(select); // Then const selectedOption = await p.getSelectedOptionOf(select); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(selectedOption.label).toBe('Select 1 - label 2'); }); });