UNPKG

playwright-fluent

Version:
77 lines (76 loc) 3.46 kB
"use strict"; 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")); describe('handle has 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 true when selector has expected 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, 'has-handle-aria-label.test.html')}`; await page.goto(url); const selector = '#with-aria-label'; const handle = await page.$(selector); // When const result = await SUT.hasHandleAriaLabel(handle, 'label for this input field'); // Then expect(handle).toBeDefined(); expect(result).toBe(true); await browser.close(); }); test('should return false when selector has no 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, 'has-handle-aria-label.test.html')}`; await page.goto(url); const selector = '#with-no-aria-label'; const handle = await page.$(selector); // When const result = await SUT.hasHandleAriaLabel(handle, 'foobar'); // Then expect(handle).toBeDefined(); expect(result).toBe(false); await browser.close(); }); test('should return false when selector has empty 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, 'has-handle-aria-label.test.html')}`; await page.goto(url); const selector = '#with-empty-aria-label'; const handle = await page.$(selector); // When const result = await SUT.hasHandleAriaLabel(handle, 'foobar'); // Then expect(handle).toBeDefined(); expect(result).toBe(false); await browser.close(); }); test('should return false when aria-label does not match', 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, 'has-handle-aria-label.test.html')}`; await page.goto(url); const selector = '#with-aria-label'; const handle = await page.$(selector); // When const result = await SUT.hasHandleAriaLabel(handle, 'foobar'); // Then expect(handle).toBeDefined(); expect(result).toBe(false); await browser.close(); }); });