UNPKG

playwright-fluent

Version:
67 lines (66 loc) 3.13 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 handle_actions_1 = require("../../../handle-actions"); describe('switch from selector to iframe', () => { let browser = undefined; // eslint-disable-next-line @typescript-eslint/no-empty-function beforeEach(() => { }); afterEach(async () => { if (browser) { await browser.close(); browser = undefined; } }); test('should throw when selector is not found - 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, 'switch-from-selector-to-iframe.test.html')}`; await page.goto(url); const options = { ...handle_actions_1.defaultSwitchToIframeOptions, timeoutInMilliseconds: 1000, }; // When // Then const expectedError = new Error("Selector 'foobar' was not found in DOM"); await SUT.switchFromSelectorToIframe('foobar', page, options).catch((error) => expect(error).toMatchObject(expectedError)); }); test('should throw when no browser has been launched', async () => { // Given const page = undefined; const options = { ...handle_actions_1.defaultSwitchToIframeOptions, timeoutInMilliseconds: 1000, }; // When // Then const expectedError = new Error("Cannot switch to iframe from 'foobar' because no browser has been launched"); await SUT.switchFromSelectorToIframe('foobar', page, options).catch((error) => expect(error).toMatchObject(expectedError)); }); test('should throw when selector is not an iframe - 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, 'switch-from-selector-to-iframe.test.html')}`; await page.goto(url); const options = { ...handle_actions_1.defaultSwitchToIframeOptions, timeoutInMilliseconds: 2000, }; const iframeSelector = 'div#iframe-label'; // When // Then const expectedError = new Error(`Cannot switch to iframe from '${iframeSelector}' because this selector does not seem to be an iframe.`); await SUT.switchFromSelectorToIframe(iframeSelector, page, options).catch((error) => expect(error).toMatchObject(expectedError)); }); });