weikaopu-wdio-ui5-service
Version:
WebdriverIO plugin for testing UI5 browser-based apps
223 lines • 12.1 kB
JavaScript
"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 });
var wdi5_bridge_js_1 = require("./lib/wdi5-bridge.js");
var Logger_js_1 = require("./lib/Logger.js");
var Logger = Logger_js_1.Logger.getInstance();
var Service = /** @class */ (function () {
function Service(_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
Service.prototype.before = function ( /*capabilities* , specs*/) {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, name_1, e_1_1;
var e_1, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
// 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"] = {};
}
return [4 /*yield*/, (0, wdi5_bridge_js_1.start)(this._config)];
case 1:
_d.sent();
Logger.info("started");
return [4 /*yield*/, (0, wdi5_bridge_js_1.setup)(this._config)];
case 2:
_d.sent();
Logger.info("setup complete");
if (!browser.isMultiremote) return [3 /*break*/, 16];
_d.label = 3;
case 3:
_d.trys.push([3, 13, 14, 15]);
_a = __values(browser.instances), _b = _a.next();
_d.label = 4;
case 4:
if (!!_b.done) return [3 /*break*/, 12];
name_1 = _b.value;
if (!this._capabilities[name_1].capabilities["wdi5:authentication"]) return [3 /*break*/, 6];
return [4 /*yield*/, (0, wdi5_bridge_js_1.authenticate)(this._capabilities[name_1].capabilities["wdi5:authentication"], name_1)];
case 5:
_d.sent();
_d.label = 6;
case 6:
if (!this._config.wdi5.skipInjectUI5OnStart) return [3 /*break*/, 7];
Logger.warn("skipped wdi5 injection!");
return [3 /*break*/, 11];
case 7:
if (!this._config.wdi5.btpWorkZoneEnablement) return [3 /*break*/, 9];
Logger.info("delegating wdi5 injection to WorkZone enablement...");
return [4 /*yield*/, this.enableBTPWorkZoneStdEdition(browser[name_1])];
case 8:
_d.sent();
return [3 /*break*/, 11];
case 9: return [4 /*yield*/, this.injectUI5(browser[name_1])];
case 10:
_d.sent();
_d.label = 11;
case 11:
_b = _a.next();
return [3 /*break*/, 4];
case 12: return [3 /*break*/, 15];
case 13:
e_1_1 = _d.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 15];
case 14:
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 15: return [3 /*break*/, 23];
case 16:
if (!this._capabilities["wdi5:authentication"]) return [3 /*break*/, 18];
return [4 /*yield*/, (0, wdi5_bridge_js_1.authenticate)(this._capabilities["wdi5:authentication"])];
case 17:
_d.sent();
_d.label = 18;
case 18:
if (!this._config.wdi5.skipInjectUI5OnStart) return [3 /*break*/, 19];
Logger.warn("skipped wdi5 injection!");
return [3 /*break*/, 23];
case 19:
if (!this._config.wdi5.btpWorkZoneEnablement) return [3 /*break*/, 21];
Logger.info("delegating wdi5 injection to WorkZone enablement...");
return [4 /*yield*/, this.enableBTPWorkZoneStdEdition(browser)];
case 20:
_d.sent();
return [3 /*break*/, 23];
case 21: return [4 /*yield*/, this.injectUI5(browser)];
case 22:
_d.sent();
_d.label = 23;
case 23: return [2 /*return*/];
}
});
});
};
/**
* 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
*/
Service.prototype.enableBTPWorkZoneStdEdition = function (browser) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, $("iframe").waitForExist()]; //> wz only has a single iframe (who's id is also not updated upon subsequent app navigation)
case 1:
_a.sent(); //> wz only has a single iframe (who's id is also not updated upon subsequent app navigation)
return [4 /*yield*/, browser.switchToFrame(null)];
case 2:
_a.sent();
if (!this._config.wdi5.skipInjectUI5OnStart) return [3 /*break*/, 3];
Logger.warn("also skipped wdi5 injection in WorkZone std ed's shell!");
return [3 /*break*/, 5];
case 3: return [4 /*yield*/, this.injectUI5(browser)];
case 4:
_a.sent();
Logger.debug("injected wdi5 into the WorkZone std ed's shell!");
_a.label = 5;
case 5: return [4 /*yield*/, browser.switchToFrame(0)];
case 6:
_a.sent();
if (!this._config.wdi5.skipInjectUI5OnStart) return [3 /*break*/, 7];
Logger.warn("also skipped wdi5 injection in application iframe!");
return [3 /*break*/, 9];
case 7: return [4 /*yield*/, this.injectUI5(browser)];
case 8:
_a.sent();
Logger.debug("injected wdi5 into the WorkZone std ed's iframe containing the target app!");
_a.label = 9;
case 9: return [2 /*return*/];
}
});
});
};
/**
* 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
*/
Service.prototype.injectUI5 = function () {
return __awaiter(this, arguments, void 0, function (browserInstance) {
var config;
if (browserInstance === void 0) { browserInstance = browser; }
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, wdi5_bridge_js_1.checkForUI5Page)(browserInstance)];
case 1:
if (!_a.sent()) return [3 /*break*/, 3];
config = this._config ? this._config : browserInstance.options;
if (!config["wdi5"]) {
//Fetching config from global variable
config["wdi5"] = global.__wdi5Config.wdi5;
}
return [4 /*yield*/, (0, wdi5_bridge_js_1.injectUI5)(config, browserInstance)];
case 2:
_a.sent();
return [3 /*break*/, 4];
case 3: throw new Error("wdi5: no UI5 page/app present to work on :(");
case 4: return [2 /*return*/];
}
});
});
};
return Service;
}());
exports.default = Service;
//# sourceMappingURL=service.js.map