UNPKG

playwright-fluent

Version:
77 lines (76 loc) 3.36 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 role', () => { // 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 role', 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-role.test.html')}`; await page.goto(url); const selector = '#with-role'; const handle = await page.$(selector); // When const result = await SUT.hasHandleRole(handle, 'role of this input field'); // Then expect(handle).toBeDefined(); expect(result).toBe(true); await browser.close(); }); test('should return false when selector has no role', 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-role.test.html')}`; await page.goto(url); const selector = '#with-no-role'; const handle = await page.$(selector); // When const result = await SUT.hasHandleRole(handle, 'foobar'); // Then expect(handle).toBeDefined(); expect(result).toBe(false); await browser.close(); }); test('should return false when selector has empty role', 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-role.test.html')}`; await page.goto(url); const selector = '#with-empty-role'; const handle = await page.$(selector); // When const result = await SUT.hasHandleRole(handle, 'foobar'); // Then expect(handle).toBeDefined(); expect(result).toBe(false); await browser.close(); }); test('should return false when role 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-role.test.html')}`; await page.goto(url); const selector = '#with-role'; const handle = await page.$(selector); // When const result = await SUT.hasHandleRole(handle, 'foobar'); // Then expect(handle).toBeDefined(); expect(result).toBe(false); await browser.close(); }); });