UNPKG

playwright-fluent

Version:
73 lines (72 loc) 3.73 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 dom_actions_1 = require("../../../dom-actions"); const is_handle_checked_1 = require("../../is-handle-checked"); const is_handle_visible_1 = require("../../is-handle-visible"); const has_handle_focus_1 = require("../../has-handle-focus"); describe('invoke method on handle', () => { let browser = undefined; // eslint-disable-next-line @typescript-eslint/no-empty-function beforeEach(() => { }); afterEach(async () => { if (browser) { await browser.close(); } }); test('should invoke method click and focus on checkbox - chromium', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true }); 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, 'invoke-method-on-handle.test.html')}`; await page.goto(url); // When const selector = '#unchecked-and-enabled'; const handle = await page.$(selector); await SUT.invokeMethodOnHandle('click', handle, selector); await SUT.invokeMethodOnHandle('focus', handle, selector); // Then expect(handle).toBeDefined(); expect(await (0, has_handle_focus_1.hasHandleFocus)(handle)).toBe(true); expect(await (0, is_handle_checked_1.isHandleChecked)(handle, is_handle_visible_1.defaultVerboseOptions)).toBe(true); }); test('should invoke method click/focus/blur on checkbox - chromium', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true }); 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, 'invoke-method-on-handle.test.html')}`; await page.goto(url); // When const selector = '#unchecked-and-enabled'; const handle = await page.$(selector); await SUT.invokeMethodOnHandle('click', handle, selector); await SUT.invokeMethodOnHandle('focus', handle, selector); await SUT.invokeMethodOnHandle('blur', handle, selector); // Then expect(handle).toBeDefined(); expect(await (0, has_handle_focus_1.hasHandleFocus)(handle)).toBe(false); expect(await (0, is_handle_checked_1.isHandleChecked)(handle, is_handle_visible_1.defaultVerboseOptions)).toBe(true); }); test('should throw when the method does not exist - chromium', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true }); 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, 'invoke-method-on-handle.test.html')}`; await page.goto(url); // When const selector = '#unchecked-and-enabled'; const handle = await page.$(selector); // Then const expectedError = new Error("Cannot invoke method 'foo' on '#unchecked-and-enabled' because this method does not exist."); await SUT.invokeMethodOnHandle('foo', handle, selector).catch((error) => expect(error).toMatchObject(expectedError)); }); });