UNPKG

wdio-ui5-service

Version:

WebdriverIO plugin for testing UI5 browser-based apps

42 lines 2 kB
//> REVISIT: do we need this at all? // -> as .fireEvent on a UI5 control in Node.js-scope is discouraged async function clientSide_fireEvent(webElement, eventName, oOptions, browserInstance) { return await browserInstance.execute(async function wdi5_fireEvent(webElement, eventName, oOptions) { if (!window.wdi5 || !window.bridge) { // Local checkForWdi5BrowserReady.js for better performance const wdi5MissingErr = new Error(`WDI5 is not available in the browser context! window.wdi5: ${!!window.wdi5} | window.bridge: ${!!window.bridge}`); console.error(wdi5MissingErr); // eslint-disable-line no-console throw wdi5MissingErr; } try { await window.bridge.waitForUI5(window.wdi5.waitForUI5Options); } catch (error) { return window.wdi5.errorHandling(error); } window.wdi5.Log.info("[browser wdi5] working " + eventName + " for " + webElement); // DOM to ui5 const oControl = window.wdi5.getUI5CtlForWebObj(webElement); if (oControl && oControl.hasListeners(eventName)) { window.wdi5.Log.info("[browser wdi5] firing " + eventName + " on " + webElement); // element existent and has the target event try { // eval the options indicated by option of type string if (typeof oOptions === "string") { oOptions = eval(oOptions)(); } oControl.fireEvent(eventName, oOptions); // convert to boolean return { status: 0, result: true }; } catch (error) { return window.wdi5.errorHandling(error); } } else { return window.wdi5.errorHandling("no control and/or no event listener found for " + eventName); } }, webElement, eventName, oOptions); } export { clientSide_fireEvent }; //# sourceMappingURL=fireEvent.js.map