playwright-fluent
Version:
Fluent API around playwright
80 lines (79 loc) • 3.9 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const path = tslib_1.__importStar(require("path"));
const playwright_1 = require("playwright");
const SUT = tslib_1.__importStar(require("../index"));
const page_actions_1 = require("../../../page-actions");
describe('get next siblings', () => {
let browser = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
beforeEach(() => { });
afterEach(async () => {
if (browser) {
await browser.close();
}
});
test('should return an empty array when root elements is empty', async () => {
// Given
// When
const result = await SUT.getNextSiblingsOf([]);
// Then
expect(Array.isArray(result)).toBe(true);
expect(result.length).toBe(0);
});
test('should get next siblings', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'get-next-sibling-of-handles.test.html')}`;
await page.goto(url);
// When
const rootElements = await (0, page_actions_1.querySelectorAllInPage)('[role="row"]', page);
const result = await SUT.getNextSiblingsOf(rootElements);
// Then
expect(rootElements.length).toBe(3);
expect(Array.isArray(result)).toBe(true);
expect(result.length).toBe(2);
expect(await result[0].evaluate((node) => node.tagName)).toContain('TR');
expect(await result[0].evaluate((node) => node.getAttribute('data-test-id'))).toBe('row2');
expect(await result[1].evaluate((node) => node.tagName)).toContain('TR');
expect(await result[1].evaluate((node) => node.getAttribute('data-test-id'))).toBe('row3');
});
test('should get next sibling', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'get-next-sibling-of-handles.test.html')}`;
await page.goto(url);
// When
const rootElements = await (0, page_actions_1.querySelectorAllInPage)('select[data-test-id="my-select2"] option', page);
const firstOption = rootElements[0];
const result = await SUT.getNextSiblingsOf([firstOption]);
// Then
expect(Array.isArray(result)).toBe(true);
expect(result.length).toBe(1);
expect(await firstOption.evaluate((node) => node.tagName)).toContain('OPTION');
expect(await firstOption.evaluate((node) => node.innerText)).toBe('Select 2 - label 1');
const nextOption = result[0];
expect(await nextOption.evaluate((node) => node.tagName)).toContain('OPTION');
expect(await nextOption.evaluate((node) => node.innerText)).toBe('Select 2 - label 2');
});
test('should return no elements when sibling is not found', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'get-next-sibling-of-handles.test.html')}`;
await page.goto(url);
// When
const rootElements = await (0, page_actions_1.querySelectorAllInPage)('html', page);
const result = await SUT.getNextSiblingsOf(rootElements);
// Then
expect(rootElements.length).toBe(1);
expect(Array.isArray(result)).toBe(true);
expect(result.length).toBe(0);
});
});
;