UNPKG

playwright-fluent

Version:
115 lines (114 loc) 5.72 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")); const has_handle_focus_1 = require("../../has-handle-focus"); const dom_actions_1 = require("../../../dom-actions"); const check_handle_1 = require("../check-handle"); const is_handle_checked_1 = require("../../is-handle-checked"); const utils_1 = require("../../../../utils"); describe.skip('check handle', () => { let browser = undefined; // eslint-disable-next-line @typescript-eslint/no-empty-function beforeEach(() => { }); afterEach(async () => { if (browser) { await browser.close(); } }); test('should throw when selector is undefined - chrome', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true, executablePath: (0, utils_1.getChromeCanaryPath)() }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); const url = `file:${path.join(__dirname, 'check-handle.test.html')}`; await page.goto(url); // When // Then const expectedError = new Error("Cannot check 'foobar' because selector was not found in DOM"); await SUT.checkHandle(undefined, 'foobar', page, check_handle_1.defaultCheckOptions).catch((error) => expect(error).toMatchObject(expectedError)); }); test('should throw when selector is null - chrome', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true, executablePath: (0, utils_1.getChromeCanaryPath)() }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); const url = `file:${path.join(__dirname, 'check-handle.test.html')}`; await page.goto(url); // When // Then const expectedError = new Error("Cannot check 'foobar' because selector was not found in DOM"); await SUT.checkHandle(null, 'foobar', page, check_handle_1.defaultCheckOptions).catch((error) => expect(error).toMatchObject(expectedError)); }); test('should throw when selector is disabled and unchecked - chrome', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true, executablePath: (0, utils_1.getChromeCanaryPath)() }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); await (0, dom_actions_1.showMousePosition)(page); const url = `file:${path.join(__dirname, 'check-handle.test.html')}`; await page.goto(url); const checkOptions = { ...check_handle_1.defaultCheckOptions, timeoutInMilliseconds: 1000, verbose: false, }; // When const selector = '#unchecked-and-disabled'; const handle = await page.$(selector); let result = undefined; try { await SUT.checkHandle(handle, selector, page, checkOptions); } catch (error) { result = error; } // Then expect(handle).toBeDefined(); expect(await (0, is_handle_checked_1.isHandleChecked)(handle, { verbose: checkOptions.verbose })).toBe(false); expect(result && result.message).toContain("Cannot check '#unchecked-and-disabled' because this selector is disabled"); }); test('should do nothing when selector is already checked - chrome', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true, executablePath: (0, utils_1.getChromeCanaryPath)() }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); await (0, dom_actions_1.showMousePosition)(page); const url = `file:${path.join(__dirname, 'check-handle.test.html')}`; await page.goto(url); const checkOptions = { ...check_handle_1.defaultCheckOptions, verbose: false, }; // When const selector = '#already-checked'; const handle = await page.$(selector); await SUT.checkHandle(handle, selector, page, checkOptions); // Then expect(handle).toBeDefined(); expect(await (0, is_handle_checked_1.isHandleChecked)(handle, { verbose: checkOptions.verbose })).toBe(true); }); test('should wait for the selector to be enabled - chrome', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true, executablePath: (0, utils_1.getChromeCanaryPath)() }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); await (0, dom_actions_1.showMousePosition)(page); const url = `file:${path.join(__dirname, 'check-handle.test.html')}`; await page.goto(url); const checkOptions = { ...check_handle_1.defaultCheckOptions, verbose: false, }; // When const selector = '#disabled-then-enabled'; const handle = await page.$('#disabled-then-enabled'); await SUT.checkHandle(handle, selector, page, checkOptions); // Then expect(handle).toBeDefined(); expect(await (0, has_handle_focus_1.hasHandleFocus)(handle)).toBe(true); expect(await (0, is_handle_checked_1.isHandleChecked)(handle, { verbose: checkOptions.verbose })).toBe(true); }); });