Skip to content

Commit

Permalink
feat: hook up wdi5 commands to wdio
Browse files Browse the repository at this point in the history
  • Loading branch information
vobu committed Dec 3, 2021
1 parent 54ecae7 commit 37e55bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/lib/wdi5-bridge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Logger as _Logger } from "./Logger"
import { wdi5Config } from "../types/wdi5.types"

import { addWdi5Commands } from "./wdi5-commands"

import { Logger as _Logger } from "./Logger"
const Logger = _Logger.getInstance()

export async function start(config: wdi5Config) {
Expand All @@ -14,6 +17,8 @@ export async function start(config: wdi5Config) {
Logger.info("open url with fallback '#' (this is not causing any issues since its is removed for navigation)")
await browser.url("#")
}

addWdi5Commands()
}

export async function injectUI5() {}
28 changes: 15 additions & 13 deletions src/lib/wdi5-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ function _createWdioUI5KeyFromSelector(selector: wdi5Selector): string {
return wdi5_ui5_key
}

browser.addCommand("asControl", (wdi5Selector: wdi5Selector) => {
const internalKey = wdi5Selector.wdio_ui5_key || _createWdioUI5KeyFromSelector(wdi5Selector)
// either retrieve and cache a UI5 control
// or return a cached version
if (!browser._controls[internalKey] || wdi5Selector.forceSelect /* always retrieve control */) {
Logger.info(`creating internal control with id ${internalKey}`)
const wdi5Control = {}
browser._controls[internalKey] = wdi5Control
} else {
Logger.info(`reusing internal control with id ${internalKey}`)
return browser._controls[internalKey]
}
})
export function addWdi5Commands() {
browser.addCommand("asControl", async (wdi5Selector: wdi5Selector) => {
const internalKey = wdi5Selector.wdio_ui5_key || _createWdioUI5KeyFromSelector(wdi5Selector)
// either retrieve and cache a UI5 control
// or return a cached version
if (!browser._controls[internalKey] || wdi5Selector.forceSelect /* always retrieve control */) {
Logger.info(`creating internal control with id ${internalKey}`)
const wdi5Control = {}
browser._controls[internalKey] = wdi5Control
} else {
Logger.info(`reusing internal control with id ${internalKey}`)
return browser._controls[internalKey]
}
})
}

0 comments on commit 37e55bd

Please # to comment.