playwright-fluent
Version:
Fluent API around playwright
91 lines (90 loc) • 3.54 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 - withPlaceholder', () => {
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-placeholder.test.html')}`;
// prettier-ignore
await p
.withBrowser('chromium')
.withOptions({ headless: true })
.navigateTo(url);
// When
const selector = p.selector('[role="row"]').find('foobar').withPlaceholder('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-placeholder.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('input')
.withPlaceholder('foo bar');
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.value)).toBe('');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(await firstHandle.evaluate((node) => node.value)).toBe('');
expect(await handles[1].evaluate((node) => node.value)).toBe('foobar');
expect(selector.toString()).toBe(`selector([role="row"])
.find(td)
.find(input)
.withPlaceholder(foo bar)`);
});
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('input')
.withPlaceholder('foo bar');
const url = `file:${path.join(__dirname, 'with-placeholder.test.html')}`;
// prettier-ignore
await p
.withBrowser('chromium')
.withOptions({ headless: true })
.navigateTo(url)
.click(selector)
.typeText('yo');
// 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.value)).toBe('yo');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(await firstHandle.evaluate((node) => node.value)).toBe('yo');
expect(await handles[1].evaluate((node) => node.value)).toBe('foobar');
expect(selector.toString()).toBe(`selector([role="row"])
.find(td)
.find(input)
.withPlaceholder(foo bar)`);
});
});
;