wdio-ui5-service
Version:
WebdriverIO plugin for testing UI5 browser-based apps
73 lines • 2.63 kB
JavaScript
import { clientSide_executeObjectMethod } from "../../client-side-js/executeObjectMethod.cjs";
import { Logger as _Logger } from "./Logger.js";
const Logger = _Logger.getInstance();
/**
* equivalent representation of a sap.ui.base.Object in Node.js-scope
*/
export 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 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)}`);
}
}
}
//# sourceMappingURL=wdi5-object.js.map