wdio-ui5-service
Version:
WebdriverIO plugin for testing UI5 browser-based apps
173 lines • 8.04 kB
JavaScript
;
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.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WDI5Object = void 0;
var executeObjectMethod_cjs_1 = require("../../client-side-js/executeObjectMethod.cjs");
var Logger_js_1 = require("./Logger.js");
var Logger = Logger_js_1.Logger.getInstance();
/**
* equivalent representation of a sap.ui.base.Object in Node.js-scope
*/
var WDI5Object = /** @class */ (function () {
function WDI5Object(uuid, aProtoFunctions, object) {
this._uuid = uuid;
if (aProtoFunctions) {
this._aProtoFunctions = aProtoFunctions;
this._attachObjectMethods(this._aProtoFunctions);
}
else {
Logger.warn("creating object: ".concat(uuid, " without functions"));
}
if (object) {
this._baseObject = object;
this._attachObjectProperties(this._baseObject);
}
else {
Logger.warn("creating object: ".concat(uuid, " without properties"));
}
}
WDI5Object.prototype.getUUID = function () {
return this._uuid;
};
WDI5Object.prototype._attachObjectProperties = function (oObject) {
var e_1, _a;
try {
for (var _b = __values(Object.entries(oObject)), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
this[key] = value;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
};
WDI5Object.prototype._excuteObjectMethod = function (methodName, uuid) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, executeObjectMethod_cjs_1.clientSide_executeObjectMethod)(uuid, methodName, args)];
case 1:
result = (_a.sent());
// create logging
this._writeObjectResultLog(result, methodName);
if (result.returnType === "object") {
return [2 /*return*/, new WDI5Object(result.uuid, result.aProtoFunctions, result.object)];
}
else {
return [2 /*return*/, result.result];
}
return [2 /*return*/];
}
});
});
};
WDI5Object.prototype._attachObjectMethods = function (sReplFunctionNames) {
var _this = this;
// loop over methods and attach
// check the validity of param
if (sReplFunctionNames) {
sReplFunctionNames.forEach(function (sMethodName) { return __awaiter(_this, void 0, void 0, function () {
var _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = this;
_b = sMethodName;
return [4 /*yield*/, this._excuteObjectMethod.bind(this, sMethodName, this._uuid)];
case 1:
_a[_b] = _c.sent();
return [2 /*return*/];
}
});
}); });
}
else {
Logger.warn("".concat(this._uuid, " has no sReplFunctionNames"));
}
};
WDI5Object.prototype._writeObjectResultLog = function (response, functionName) {
if (response.status > 0) {
Logger.error("call of ".concat(functionName, " failed because of: ").concat(response.message));
}
else if (response.status === 0) {
Logger.success("call of function ".concat(functionName, " returned: ").concat(JSON.stringify(response.id ? response.id : response.result)));
}
else {
Logger.warn("Unknown status: ".concat(functionName, " returned: ").concat(JSON.stringify(response.message)));
}
};
return WDI5Object;
}());
exports.WDI5Object = WDI5Object;
//# sourceMappingURL=wdi5-object.js.map