playwright-fluent
Version: 
Fluent API around playwright
52 lines (51 loc) • 2.41 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 aria-label', () => {
    // eslint-disable-next-line @typescript-eslint/no-empty-function
    beforeEach(() => { });
    // eslint-disable-next-line @typescript-eslint/no-empty-function
    afterEach(async () => { });
    test('should return an empty array when root elements is empty', async () => {
        // Given
        // When
        const result = await SUT.getHandlesWithAriaLabel('foobar', []);
        // Then
        expect(Array.isArray(result)).toBe(true);
        expect(result.length).toBe(0);
    });
    test('should return inputs with the aria-label', async () => {
        // Given
        const 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-aria-label.test.html')}`;
        await page.goto(url);
        // When
        const inputElements = await (0, page_actions_1.querySelectorAllInPage)('[role="row"] input', page);
        const result = await SUT.getHandlesWithAriaLabel('foo bar', inputElements);
        // Then
        expect(inputElements.length).toBe(8);
        expect(result.length).toBe(2);
        await browser.close();
    });
    test('should return no elements when aria-label is not found', async () => {
        // Given
        const 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-aria-label.test.html')}`;
        await page.goto(url);
        // When
        const rootElements = await (0, page_actions_1.querySelectorAllInPage)('[role="row"] input', page);
        const result = await SUT.getHandlesWithAriaLabel('foobar', rootElements);
        // Then
        expect(rootElements.length).toBe(8);
        expect(result.length).toBe(0);
        await browser.close();
    });
});