playwright-fluent
Version:
Fluent API around playwright
54 lines (53 loc) • 2.38 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 elements with placeholder', () => {
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.getHandlesWithPlaceholder('foobar', []);
// Then
expect(Array.isArray(result)).toBe(true);
expect(result.length).toBe(0);
});
test('should return inputs with the placeholder', 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-handles-with-placeholder.test.html')}`;
await page.goto(url);
// When
const inputElements = await (0, page_actions_1.querySelectorAllInPage)('[role="row"] input', page);
const result = await SUT.getHandlesWithPlaceholder('foo bar', inputElements);
// Then
expect(inputElements.length).toBe(5);
expect(result.length).toBe(2);
});
test('should return no elements when placeholder 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-handles-with-placeholder.test.html')}`;
await page.goto(url);
// When
const rootElements = await (0, page_actions_1.querySelectorAllInPage)('[role="row"] input', page);
const result = await SUT.getHandlesWithPlaceholder('foobar', rootElements);
// Then
expect(rootElements.length).toBe(5);
expect(result.length).toBe(0);
});
});
;