playwright-fluent
Version:
Fluent API around playwright
87 lines (86 loc) • 2.87 kB
JavaScript
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 - parent', () => {
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, 'parent.test.html')}`;
// prettier-ignore
await p
.withBrowser('chromium')
.withOptions({ headless: true })
.withCursor()
.navigateTo(url);
// When
// prettier-ignore
const selector = p
.selector('[role="row"]')
.withText('foobar')
.parent();
const handles = await selector.getAllHandles();
// Then
expect(Array.isArray(handles)).toBe(true);
expect(handles.length).toBe(0);
});
test('should get parent handle', async () => {
// Given
const url = `file:${path.join(__dirname, 'parent.test.html')}`;
// prettier-ignore
await p
.withBrowser('chromium')
.withOptions({ headless: true })
.withCursor()
.navigateTo(url);
// When
// prettier-ignore
const selector = p
.selector('[role="row"]')
.find('td')
.withText('row2')
.parent();
const handles = await selector.getAllHandles();
// Then
expect(Array.isArray(handles)).toBe(true);
expect(handles.length).toBe(1);
expect(await handles[0].evaluate((node) => node.tagName)).toBe('TR');
expect(selector.toString()).toBe(`selector([role="row"])
.find(td)
.withText(row2)
.parent()`);
});
test('should get handles, even when selector is created before page is instanciated', async () => {
// Given
// prettier-ignore
const selector = p
.selector('[role="row"]')
.find('td')
.withText('row2')
.parent();
const url = `file:${path.join(__dirname, 'parent.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(1);
expect(await handles[0].evaluate((node) => node.tagName)).toBe('TR');
expect(selector.toString()).toBe(`selector([role="row"])
.find(td)
.withText(row2)
.parent()`);
});
});
;