UNPKG

@redhat-developer/page-objects

Version:

Page Object API implementation for a VS Code editor used by ExTester framework.

86 lines 3.72 kB
"use strict"; /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License", destination); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const selenium_webdriver_1 = require("selenium-webdriver"); const AbstractElement_1 = require("./AbstractElement"); /** * Returns a class that has the ability to access a webview. * * @param Base the class to mixin * @returns a class that has the ability to access a webview */ function default_1(Base) { return class extends Base { /** * Cannot use static element, since this class is unnamed. */ handle; /** * Search for an element inside the webview iframe. * Requires webdriver being switched to the webview iframe first. * (Will attempt to search from the main DOM root otherwise) * * @param locator webdriver locator to search by * @returns promise resolving to WebElement when found */ async findWebElement(locator) { return await this.getDriver().findElement(locator); } /** * Search for all element inside the webview iframe by a given locator * Requires webdriver being switched to the webview iframe first. * (Will attempt to search from the main DOM root otherwise) * * @param locator webdriver locator to search by * @returns promise resolving to a list of WebElement objects */ async findWebElements(locator) { return await this.getDriver().findElements(locator); } /** * Switch the underlying webdriver context to the webview iframe. * This allows using the findWebElement methods. * Note that only elements inside the webview iframe will be accessible. * Use the switchBack method to switch to the original context. */ async switchToFrame(timeout = 5000) { if (!this.handle) { this.handle = await this.getDriver().getWindowHandle(); } const view = await this.getViewToSwitchTo(); if (!view) { return; } await this.getDriver().switchTo().frame(view); await this.getDriver().wait(selenium_webdriver_1.until.elementLocated(AbstractElement_1.AbstractElement.locators.WebView.activeFrame), timeout); const frame = await this.getDriver().findElement(AbstractElement_1.AbstractElement.locators.WebView.activeFrame); await this.getDriver().switchTo().frame(frame); } /** * Switch the underlying webdriver back to the original window */ async switchBack() { if (!this.handle) { this.handle = await this.getDriver().getWindowHandle(); } return await this.getDriver().switchTo().window(this.handle); } }; } //# sourceMappingURL=WebviewMixin.js.map