wdio-ui5-service
Version:
WebdriverIO plugin for testing UI5 browser-based apps
118 lines • 5.63 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const wdi5_bridge_js_1 = require("./lib/wdi5-bridge.js");
const wdi5_js_1 = require("./wdi5.js");
const Logger_js_1 = require("./lib/Logger.js");
const Logger = Logger_js_1.Logger.getInstance();
class Service {
_options; // TODO: this is the successor to _config in wdio^8
_capabilities;
_config; // an enhanced version of the regular wdio config
constructor(_options, // TODO: this is the successor to _config in wdio^8
_capabilities, _config // an enhanced version of the regular wdio config
) {
this._options = _options;
this._capabilities = _capabilities;
this._config = _config;
} // the Service is instantiated by wdio with the capabilities and config passed on to
async before(capabilities, specs, browserInstance) {
// cache config to global for later use
global.__wdi5Config = this._config;
// if no wdi5 config is available we add it manually
if (!this._config?.wdi5) {
this._config.wdi5 = {};
}
await (0, wdi5_bridge_js_1.start)(this._config, browserInstance);
Logger.info("started");
await (0, wdi5_bridge_js_1.setup)(this._config, browserInstance);
Logger.info("setup complete");
if (browserInstance.isMultiremote) {
for (const name of browserInstance.instances) {
// TODO: browserInstance[name as keyof typeof browserInstance] repeated multiple times
if (this?._capabilities[name].capabilities["wdi5:authentication"]) {
await (0, wdi5_bridge_js_1.authenticate)(this._capabilities[name].capabilities["wdi5:authentication"], name);
}
if (this._config?.wdi5?.skipInjectUI5OnStart) {
Logger.warn("skipped wdi5 injection!");
}
else if (this._config?.wdi5?.btpWorkZoneEnablement) {
Logger.info("delegating wdi5 injection to WorkZone enablement...");
await this.enableBTPWorkZoneStdEdition(browserInstance[name]);
}
else {
await this.injectUI5(browserInstance[name]);
}
}
(0, wdi5_bridge_js_1.initMultiRemoteBrowser)();
}
else {
if (this?._capabilities["wdi5:authentication"]) {
await (0, wdi5_bridge_js_1.authenticate)(this._capabilities["wdi5:authentication"], "");
}
if (this._config?.wdi5?.skipInjectUI5OnStart) {
Logger.warn("skipped wdi5 injection!");
}
else if (this._config?.wdi5?.btpWorkZoneEnablement) {
Logger.info("delegating wdi5 injection to WorkZone enablement...");
await this.enableBTPWorkZoneStdEdition(browserInstance);
}
else {
await this.injectUI5(browserInstance);
}
}
}
afterCommand(commandName, args, result) {
if (commandName === "url" && result?.redirectChain?.length > 0) {
Logger.warn("Navigation redirect was detected! The requested URL might differ from the actual URL loaded in the browser.");
Logger.warn("Redirects may break tests due to the loss of WDI5 browser context!");
Logger.warn("Redirected to:", result?.url);
}
}
/**
* waits until btp's wz std ed iframe containing the target app is available,
* switches the browser context into the iframe
* and eventually injects the wdi5 into the target app
*/
async enableBTPWorkZoneStdEdition(browserInstance) {
//> wz may have many iframe, one per opened app, we need the active one
const iframe = await browserInstance.$(wdi5_js_1.wdi5.getBtpWorkZoneIframeSelector());
await iframe.waitForExist();
await browserInstance.switchFrame(null);
if (this?._config?.wdi5?.skipInjectUI5OnStart) {
Logger.warn("also skipped wdi5 injection in WorkZone std ed's shell!");
}
else {
await this.injectUI5(browserInstance);
Logger.debug("injected wdi5 into the WorkZone std ed's shell!");
}
await browserInstance.switchFrame(iframe);
if (this?._config?.wdi5?.skipInjectUI5OnStart) {
Logger.warn("also skipped wdi5 injection in application iframe!");
}
else {
await this.injectUI5(browserInstance);
Logger.debug("injected wdi5 into the WorkZone std ed's iframe containing the target app!");
}
}
/**
* this is a helper function to late-inject ui5 at test-time
* it relays the the wdio configuration (set in the .before() hook to the browser.options parameter by wdio)
* to the injectUI5 function of the actual wdi5-bridge
*/
async injectUI5(browserInstance = browser) {
if (await (0, wdi5_bridge_js_1.checkForUI5Page)(browserInstance)) {
// depending on the scenario (lateInject, multiRemote) we have to access the config differently
const config = this._config ? this._config : browserInstance.options;
if (!config?.wdi5) {
//Fetching config from global variable
config.wdi5 = global.__wdi5Config.wdi5;
}
await (0, wdi5_bridge_js_1.injectUI5)(config, browserInstance);
}
else {
throw new Error("wdi5: no UI5 page/app present to work on :(");
}
}
}
exports.default = Service;
//# sourceMappingURL=service.js.map