playwright-fluent
Version:
Fluent API around playwright
84 lines (83 loc) • 4.17 kB
JavaScript
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 switch_from_handle_to_iframe_1 = require("../switch-from-handle-to-iframe");
describe('switch from handle 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 undefined - 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-handle-to-iframe.test.html')}`;
await page.goto(url);
const options = {
...switch_from_handle_to_iframe_1.defaultSwitchToIframeOptions,
timeoutInMilliseconds: 1000,
};
// When
// Then
const expectedError = new Error("Cannot switch to iframe from 'foobar' because selector was not found in DOM");
await SUT.switchFromHandleToIframe(undefined, 'foobar', page, options).catch((error) => expect(error).toMatchObject(expectedError));
});
test('should throw when selector is null - 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-handle-to-iframe.test.html')}`;
await page.goto(url);
const options = {
...switch_from_handle_to_iframe_1.defaultSwitchToIframeOptions,
timeoutInMilliseconds: 1000,
};
// When
// Then
const expectedError = new Error("Cannot switch to iframe from 'foobar' because selector was not found in DOM");
await SUT.switchFromHandleToIframe(null, '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 = {
...switch_from_handle_to_iframe_1.defaultSwitchToIframeOptions,
timeoutInMilliseconds: 1000,
};
// When
// Then
const expectedError = new Error("Cannot switch to iframe from 'foobar' because no browser has been launched");
await SUT.switchFromHandleToIframe(null, '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-handle-to-iframe.test.html')}`;
await page.goto(url);
const options = {
...switch_from_handle_to_iframe_1.defaultSwitchToIframeOptions,
timeoutInMilliseconds: 2000,
};
// When
// Then
const expectedError = new Error("Cannot switch to iframe from 'foobar' because this selector does not seem to be an iframe.");
const iframeHandle = await page.$('div#iframe-label');
await SUT.switchFromHandleToIframe(iframeHandle, 'foobar', page, options).catch((error) => expect(error).toMatchObject(expectedError));
});
});
;