Skip to content

Commit

Permalink
feat: only transfer one level of an object
Browse files Browse the repository at this point in the history
Object are now transfared only one level deep.
  • Loading branch information
sebbi08 committed Jan 17, 2024
1 parent d0d6e0f commit 6af0bbc
Show file tree
Hide file tree
Showing 14 changed files with 334 additions and 188 deletions.
4 changes: 3 additions & 1 deletion client-side-js/allControls.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
async function clientSide_allControls(controlSelector, browserInstance) {
controlSelector = await Promise.resolve(controlSelector) // to plug into fluent async api
return await browserInstance.executeAsync((controlSelector, done) => {
//client-side-js/allControls.cjs
const waitForUI5Options = Object.assign({}, window.wdi5.waitForUI5Options)
if (controlSelector.timeout) {
waitForUI5Options.timeout = controlSelector.timeout
Expand All @@ -21,7 +22,8 @@ async function clientSide_allControls(controlSelector, browserInstance) {
const ui5Control = window.wdi5.getUI5CtlForWebObj(domElement)
const id = ui5Control.getId()
window.wdi5.Log.info(`[browser wdi5] control with id: ${id} located!`)
const aProtoFunctions = window.wdi5.retrieveControlMethods(ui5Control)
const { functionNames: aProtoFunctions } =
window.wdi5.retrieveControlMethodsAndFlatenObject(ui5Control)
// @type [String, String?, String, "Array of Strings"]
returnElements.push({ domElement: domElement, id: id, aProtoFunctions: aProtoFunctions })
})
Expand Down
21 changes: 5 additions & 16 deletions client-side-js/executeControlMethod.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if (global.browser) {
async function executeControlMethod(webElement, methodName, browserInstance, args) {
return await browserInstance.executeAsync(
(webElement, methodName, args, done) => {
//client-side-js/executeControlMethod.cjs
window.wdi5.waitForUI5(
window.wdi5.waitForUI5Options,
() => {
Expand Down Expand Up @@ -67,29 +68,17 @@ async function executeControlMethod(webElement, methodName, browserInstance, arg
!(result instanceof sap.ui.core.Control) &&
!(result instanceof sap.ui.core.Item)
) {
// save before manipulate
const uuid = window.wdi5.saveObject(result)

// FIXME: extract, collapse and remove cylic in 1 step
// extract the methods first
const aProtoFunctions = window.wdi5.retrieveControlMethods(result, true)

// flatten the prototype so we have all funcs available
const collapsed = window.wdi5.collapseObject(result)
// exclude cyclic references
const collapsedAndNonCyclic = JSON.parse(
JSON.stringify(collapsed, window.wdi5.getCircularReplacer())
)
// remove all empty Array elements, inlcuding private keys (starting with "_")
const semanticCleanedElements = window.wdi5.removeEmptyElements(collapsedAndNonCyclic)
const { semanticCleanedElements, uuid, aProtoFunctions, objectNames } =
window.wdi5.prepareObjectForSerialization(result)

done({
status: 0,
object: semanticCleanedElements,
returnType: "object",
aProtoFunctions: aProtoFunctions,
uuid: uuid,
nonCircularResultObject: semanticCleanedElements
nonCircularResultObject: semanticCleanedElements,
objectNames
})
} else if (
typeof result === "object" &&
Expand Down
38 changes: 9 additions & 29 deletions client-side-js/executeObjectMethod.cjs
Original file line number Diff line number Diff line change
@@ -1,58 +1,38 @@
async function clientSide_executeObjectMethod(uuid, methodName, args) {
return await browser.executeAsync(
(uuid, methodName, args, done) => {
//client-side-js/executeObjectMethod.cjs
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 () => {
window.wdi5.Log.info(`[browser wdi5] call function ${methodName} from object ${uuid}`)
// DOM to UI5
const oObject = window.wdi5.objectMap[uuid]

// execute the function
// TODO: if (methodName === "getName") { debugger }
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)
}
result = await oObject[methodName].apply(oObject, args)
} else {
result = oObject[methodName].apply(oObject, args)
}

// async message call rejected
if (threw) {
done({ status: 1, message: threwMessage })
}
// result mus be a primitive
else if (window.wdi5.isPrimitive(result)) {
// result musz be a primitive
if (window.wdi5.isPrimitive(result)) {
// getter
done({ status: 0, result: result, returnType: "result" })
} else {
// create new object
const uuid = window.wdi5.saveObject(result)
const aProtoFunctions = window.wdi5.retrieveControlMethods(result, true)

result = window.wdi5.collapseObject(result)

const collapsedAndNonCyclic = JSON.parse(
JSON.stringify(result, window.wdi5.getCircularReplacer())
)
// remove all empty Array elements, inlcuding private keys (starting with "_")
const semanticCleanedElements = window.wdi5.removeEmptyElements(collapsedAndNonCyclic)
const { semanticCleanedElements, uuid, aProtoFunctions, objectNames } =
window.wdi5.prepareObjectForSerialization(result)

done({
status: 0,
object: semanticCleanedElements,
uuid: uuid,
returnType: "object",
aProtoFunctions: aProtoFunctions
aProtoFunctions: aProtoFunctions,
objectNames
})
}
},
Expand Down
3 changes: 2 additions & 1 deletion client-side-js/getControl.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ async function clientSide_getControl(controlSelector, browserInstance) {
const id = ui5Control.getId()
const className = ui5Control.getMetadata()._sClassName
window.wdi5.Log.info(`[browser wdi5] control with id: ${id} located!`)
const aProtoFunctions = window.wdi5.retrieveControlMethods(ui5Control)
const { functionNames: aProtoFunctions } =
window.wdi5.retrieveControlMethodsAndFlatenObject(ui5Control)
done({
status: 0,
domElement: domElement,
Expand Down
16 changes: 4 additions & 12 deletions client-side-js/getObject.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,16 @@ async function clientSide_getObject(uuid) {
className = object.getMetadata()._sClassName
}
window.wdi5.Log.info(`[browser wdi5] object with uuid: ${uuid} located!`)

// FIXME: extract, collapse and remove cylic in 1 step

const aProtoFunctions = window.wdi5.retrieveControlMethods(object, true)

object = window.wdi5.collapseObject(object)

const collapsedAndNonCyclic = JSON.parse(JSON.stringify(object, window.wdi5.getCircularReplacer()))

// remove all empty Array elements, inlcuding private keys (starting with "_")
const semanticCleanedElements = window.wdi5.removeEmptyElements(collapsedAndNonCyclic)
const { semanticCleanedElements, aProtoFunctions, objectNames } =
window.wdi5.prepareObjectForSerialization(object, true)

done({
status: 0,
uuid: uuid,
aProtoFunctions: aProtoFunctions,
className: className,
object: semanticCleanedElements
object: semanticCleanedElements,
objectNames
})
},
window.wdi5.errorHandling.bind(this, done)
Expand Down
63 changes: 63 additions & 0 deletions client-side-js/getProperty.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
async function clientSide_getProperty(uuid, propertyName) {
return await browser.executeAsync(
(uuid, propertyName, done) => {
const waitForUI5Options = Object.assign({}, window.wdi5.waitForUI5Options)

window.wdi5.waitForUI5(
waitForUI5Options,
() => {
window.wdi5.Log.info(`[browser wdi5] locating property ${propertyName} from object ${uuid}`)

let object = window.wdi5.objectMap[uuid]
if (!object) {
const errorMessage = `[browser wdi5] ERR: no object with uuid: ${uuid} found`
window.wdi5.Log.error(errorMessage)
done({ status: 1, message: errorMessage })
}
object = object[propertyName]

if (!object) {
const errorMessage = `[browser wdi5] ERR: property: ${propertyName} not found on object ${uuid}`
window.wdi5.Log.error(errorMessage)
done({ status: 1, message: errorMessage })
}

let className = ""
if (object && object.getMetadata) {
className = object.getMetadata()._sClassName
}
window.wdi5.Log.info(
`[browser wdi5] property: ${propertyName} in object with uuid: ${uuid} located!`
)
if (typeof object !== "object") {
done({ status: 0, result: object })
return
}
const {
semanticCleanedElements,
aProtoFunctions,
objectNames,
uuid: newUUID
} = window.wdi5.prepareObjectForSerialization(object)

done({
status: 0,
uuid: newUUID,
aProtoFunctions: aProtoFunctions,
className: className,
object: semanticCleanedElements,
objectNames,
returnType: "object"
})
},
window.wdi5.errorHandling.bind(this, done)
)
},
uuid,
propertyName
)
}

module.exports = {
clientSide_getProperty
}
Loading

0 comments on commit 6af0bbc

Please sign in to comment.