diff --git a/client-side-js/executeObjectMethod.js b/client-side-js/executeObjectMethod.js index b6f37570..1c4bcd07 100644 --- a/client-side-js/executeObjectMethod.js +++ b/client-side-js/executeObjectMethod.js @@ -3,16 +3,35 @@ async function clientSide_executeObjectMethod(uuid, methodName, args) { (uuid, methodName, args, done) => { window.wdi5.waitForUI5( window.wdi5.waitForUI5Options, - () => { + // this callback is denoted "async" even though it is truely not + // but what other way to `await` a potentially async UI5 managed object fn in here? + async () => { // DOM to UI5 const oObject = window.wdi5.objectMap[uuid] // execute the function // TODO: if (methodName === "getName") { debugger } - let result = oObject[methodName].apply(oObject, args) + let result + let threw = false + let threwMessage = "" + if (oObject[methodName].constructor.name === "AsyncFunction") { + try { + result = await oObject[methodName].apply(oObject, args) + } catch (error) { + threw = true + threwMessage = JSON.stringify(error) + window.wdi5.Log.error(threwMessage) + } + } else { + result = oObject[methodName].apply(oObject, args) + } + // async message call rejected + if (threw) { + done({ status: 1, message: threwMessage }) + } // result mus be a primitive - if (window.wdi5.isPrimitive(result)) { + else if (window.wdi5.isPrimitive(result)) { // getter done({ status: 0, result: result, returnType: "result" }) } else { diff --git a/client-side-js/getObject.js b/client-side-js/getObject.js index ed365694..65be6e76 100644 --- a/client-side-js/getObject.js +++ b/client-side-js/getObject.js @@ -11,7 +11,7 @@ async function clientSide_getObject(uuid) { if (!object) { const errorMessage = `[browser wdi5] ERR: no object with uuid: ${uuid} found` window.wdi5.Log.error(errorMessage) - done({ status: 1, messsage: errorMessage }) + done({ status: 1, message: errorMessage }) } let className = "" diff --git a/examples/ui5-ts-app/src/controller/Main.controller.ts b/examples/ui5-ts-app/src/controller/Main.controller.ts index 290266f3..6fab1408 100644 --- a/examples/ui5-ts-app/src/controller/Main.controller.ts +++ b/examples/ui5-ts-app/src/controller/Main.controller.ts @@ -12,4 +12,15 @@ export default class Main extends BaseController { navFwd(): any { return this.getOwnerComponent().getRouter().navTo("RouteOther") } + + async asyncFn(): Promise { + return new Promise((resolve) => { + resolve(10) + }) + } + async asyncRejectFn(): Promise { + return new Promise((resolve, reject) => { + reject("meh") + }) + } } diff --git a/examples/ui5-ts-app/test/e2e/Basic.test.ts b/examples/ui5-ts-app/test/e2e/Basic.test.ts index 353d619e..329e0daa 100644 --- a/examples/ui5-ts-app/test/e2e/Basic.test.ts +++ b/examples/ui5-ts-app/test/e2e/Basic.test.ts @@ -1,5 +1,12 @@ import Button from "sap/m/Button" +import Page from "sap/m/Page" +import Controller from "sap/ui/core/mvc/Controller" +import View from "sap/ui/core/mvc/View" import { wdi5Selector } from "wdio-ui5-service/dist/types/wdi5.types" +import { wdi5 } from "wdio-ui5-service" +import * as sinon from "sinon" + +const Logger = wdi5.getLogger() describe("Basic", async () => { it("browser.allControls: check number of buttons", async () => { @@ -13,4 +20,41 @@ describe("Basic", async () => { const allButtons = (await browser.allControls(allButtonsSelector)) as unknown as Array