UNPKG

wdio-ui5-service

Version:

WebdriverIO plugin for testing UI5 browser-based apps

260 lines 13.3 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WDI5FE = void 0; var testLibrary_cjs_1 = require("../../client-side-js/testLibrary.cjs"); var Logger_js_1 = require("./Logger.js"); var Logger = Logger_js_1.Logger.getInstance(); var commonFunctions = ["and", "when", "then"]; function createProxy(myObj, type, methodCalls, pageKeys) { var thisProxy = new Proxy(myObj, { get: function (obj, prop) { if (pageKeys.indexOf(prop) !== -1) { myObj.currentMethodCall = { type: type, target: prop, methods: [] }; methodCalls.push(myObj.currentMethodCall); return thisProxy; } else if (commonFunctions.indexOf(prop) !== -1) { myObj.currentMethodCall.methods.push({ name: prop, accessor: true }); return thisProxy; } return function () { var fnArgs = []; for (var _i = 0; _i < arguments.length; _i++) { fnArgs[_i] = arguments[_i]; } myObj.currentMethodCall.methods.push({ name: prop, args: fnArgs }); return thisProxy; }; } }); return thisProxy; } var WDI5FE = /** @class */ (function () { function WDI5FE(appConfig, browserInstance, shell) { var _this = this; this.appConfig = appConfig; this.browserInstance = browserInstance; this.shell = shell; // only in the workzone context // do we need to hotwire a back navigation on the fiori shell if (shell) { this.onTheShell = { iNavigateBack: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.toShell() // eslint-disable-next-line @typescript-eslint/no-unused-vars ]; case 1: _a.sent(); // eslint-disable-next-line @typescript-eslint/no-unused-vars return [4 /*yield*/, this.shell.execute(function (Given, When, Then) { When.onTheShell.iNavigateBack(); })]; case 2: // eslint-disable-next-line @typescript-eslint/no-unused-vars _a.sent(); return [4 /*yield*/, this.toApp()]; case 3: _a.sent(); return [2 /*return*/]; } }); }); } }; } } WDI5FE.prototype.toShell = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, browser.switchToParentFrame()]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; WDI5FE.prototype.toApp = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, browser.switchToFrame(0)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; WDI5FE.initialize = function (appConfig_1) { return __awaiter(this, arguments, void 0, function (appConfig, browserInstance) { var iframe, shell, shellConfig, err_1; if (browserInstance === void 0) { browserInstance = browser; } return __generator(this, function (_a) { switch (_a.label) { case 0: // first magic wand wave -> app context return [4 /*yield*/, (0, testLibrary_cjs_1.loadFELibraries)(browserInstance)]; case 1: // first magic wand wave -> app context _a.sent(); return [4 /*yield*/, (0, testLibrary_cjs_1.initOPA)(appConfig, browserInstance) // second magic wand wave -> shell context // yet only wave the wand when there's an iframe somewhere, // indicating BTP WorkZone territory ]; case 2: _a.sent(); // second magic wand wave -> shell context // yet only wave the wand when there's an iframe somewhere, // indicating BTP WorkZone territory return [4 /*yield*/, browserInstance.switchToParentFrame() // @ts-expect-error Element cast to iframe ]; case 3: // second magic wand wave -> shell context // yet only wave the wand when there's an iframe somewhere, // indicating BTP WorkZone territory _a.sent(); return [4 /*yield*/, browserInstance.findElement("css selector", "iframe")]; case 4: iframe = _a.sent(); if (!!iframe.error) return [3 /*break*/, 11]; shellConfig = { onTheShell: { Shell: {} } }; shell = new WDI5FE(shellConfig, browserInstance); return [4 /*yield*/, (0, testLibrary_cjs_1.loadFELibraries)(browserInstance)]; case 5: _a.sent(); return [4 /*yield*/, (0, testLibrary_cjs_1.initOPA)(shellConfig, browserInstance) // back to app ]; case 6: _a.sent(); _a.label = 7; case 7: _a.trys.push([7, 9, , 10]); return [4 /*yield*/, browserInstance.switchToFrame(0) // eslint-disable-next-line @typescript-eslint/no-unused-vars ]; case 8: _a.sent(); return [3 /*break*/, 10]; case 9: err_1 = _a.sent(); // This try-catch block is a fail-safe code to make sure the execution continues if browser fails to switch to app's frame. // It has been observed that for Launchpad apps, the switchToFrame(0) is not required. Logger.info("Failed to switch to app's frame - you're probably in a Launchpad env. Continuing..."); return [3 /*break*/, 10]; case 10: return [3 /*break*/, 13]; case 11: // revert back to app context return [4 /*yield*/, browserInstance.switchToFrame(null)]; case 12: // revert back to app context _a.sent(); _a.label = 13; case 13: return [2 /*return*/, new WDI5FE(appConfig, browserInstance, shell)]; } }); }); }; WDI5FE.prototype.execute = function (fnFunction) { return __awaiter(this, void 0, void 0, function () { var methodCalls, reservedPages, Given, When, Then, addToQueueResponse, emptyQueueResponse, _a, _b, log; var e_1, _c; return __generator(this, function (_d) { switch (_d.label) { case 0: methodCalls = []; reservedPages = Object.keys(this.appConfig).concat(); Given = createProxy({}, "Given", methodCalls, reservedPages); When = createProxy({}, "When", methodCalls, reservedPages); Then = createProxy({}, "Then", methodCalls, reservedPages); fnFunction(Given, When, Then); // PrepareQueue return [4 /*yield*/, (0, testLibrary_cjs_1.addToQueue)(methodCalls, this.browserInstance)]; case 1: addToQueueResponse = _d.sent(); if (addToQueueResponse.type !== "success") { throw addToQueueResponse.message; } return [4 /*yield*/, (0, testLibrary_cjs_1.emptyQueue)(this.browserInstance)]; case 2: emptyQueueResponse = _d.sent(); if (emptyQueueResponse.type !== "success") { throw emptyQueueResponse.message; } try { for (_a = __values(emptyQueueResponse.feLogs), _b = _a.next(); !_b.done; _b = _a.next()) { log = _b.value; Logger.success("[test library] ".concat(log)); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_1) throw e_1.error; } } return [2 /*return*/]; } }); }); }; return WDI5FE; }()); exports.WDI5FE = WDI5FE; //# sourceMappingURL=wdi5-fe.js.map