UNPKG

wdio-ui5-service

Version:

WebdriverIO plugin for testing UI5 browser-based apps

77 lines 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WDI5Object = void 0; const executeObjectMethod_js_1 = require("../client-side-js/executeObjectMethod.js"); const Logger_js_1 = require("./Logger.js"); const Logger = Logger_js_1.Logger.getInstance(); /** * equivalent representation of a sap.ui.base.Object in Node.js-scope */ class WDI5Object { _uuid; _aProtoFunctions; _baseObject; constructor(uuid, aProtoFunctions, object) { this._uuid = uuid; if (aProtoFunctions) { this._aProtoFunctions = aProtoFunctions; this._attachObjectMethods(this._aProtoFunctions); } else { Logger.warn(`creating object: ${uuid} without functions`); } if (object) { this._baseObject = object; this._attachObjectProperties(this._baseObject); } else { Logger.warn(`creating object: ${uuid} without properties`); } } getUUID() { return this._uuid; } _attachObjectProperties(oObject) { for (const [key, value] of Object.entries(oObject)) { this[key] = value; } } async _excuteObjectMethod(methodName, uuid, ...args) { // call browser scope // regular browser-time execution of UI5 object method const result = await (0, executeObjectMethod_js_1.clientSide_executeObjectMethod)(uuid, methodName, args); // create logging this._writeObjectResultLog(result, methodName); if (result.returnType === "object") { return new WDI5Object(result.uuid ?? "", result.aProtoFunctions, result.object); } else { return result.result; } } _attachObjectMethods(sReplFunctionNames) { // loop over methods and attach // check the validity of param if (sReplFunctionNames) { sReplFunctionNames.forEach(async (sMethodName) => { this[sMethodName] = await this._excuteObjectMethod.bind(this, sMethodName, this._uuid); }); } else { Logger.warn(`${this._uuid} has no sReplFunctionNames`); } } _writeObjectResultLog(response, functionName) { if (response.status > 0) { Logger.error(`call of ${functionName} failed because of: ${response.message}`); } else if (response.status === 0) { Logger.success(`call of function ${functionName} returned: ${JSON.stringify(response.id ? response.id : response.result)}`); } else { Logger.warn(`Unknown status: ${functionName} returned: ${JSON.stringify(response.message)}`); } } } exports.WDI5Object = WDI5Object; //# sourceMappingURL=wdi5-object.js.map