Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combobox special case #191

Merged
merged 7 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions client-side-js/_getAggregation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
async function clientSide_getAggregation(webElement, aggregationName) {
async function clientSide_getAggregation(webElement, aggregationName, controlType) {
webElement = await Promise.resolve(webElement) // to plug into fluent async api
return await browser.executeAsync(
(webElement, aggregationName, done) => {
(webElement, aggregationName, controlType, done) => {
window.bridge.waitForUI5(window.wdi5.waitForUI5Options).then(() => {
// DOM to UI5
try {
Expand All @@ -11,15 +11,16 @@ async function clientSide_getAggregation(webElement, aggregationName) {
if (cAggregation && !Array.isArray(cAggregation)) {
cAggregation = [cAggregation]
}
let result = window.wdi5.createControlIdMap(cAggregation)
let result = window.wdi5.createControlIdMap(cAggregation, controlType)
done(["success", result])
} catch (e) {
done(["error", e.toString()])
}
})
},
webElement,
aggregationName
aggregationName,
controlType
)
}

Expand Down
7 changes: 4 additions & 3 deletions client-side-js/executeControlMethod.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
async function clientSide_executeControlMethod(webElement, methodName, args) {
async function clientSide_executeControlMethod(webElement, methodName, controlType, args) {
return await browser.executeAsync(
(webElement, methodName, args, done) => {
(webElement, methodName, controlType, args, done) => {
window.bridge.waitForUI5(window.wdi5.waitForUI5Options).then(() => {
// DOM to UI5
const oControl = window.wdi5.getUI5CtlForWebObj(webElement)
Expand All @@ -11,7 +11,7 @@ async function clientSide_executeControlMethod(webElement, methodName, args) {
// expect the method call delivers non-primitive results (like getId())
// but delivers a complex/structured type
// -> currenlty, only getAggregation(...) is supported
result = window.wdi5.createControlIdMap(result)
result = window.wdi5.createControlIdMap(result, controlType)
done(["success", result, "aggregation"])
} else {
// ui5 api <control>.focus() doesn't have return value
Expand Down Expand Up @@ -56,6 +56,7 @@ async function clientSide_executeControlMethod(webElement, methodName, args) {
},
webElement,
methodName,
controlType,
args
)
}
Expand Down
14 changes: 9 additions & 5 deletions client-side-js/injectUI5.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,19 @@ async function clientSide_injectUI5(config, waitForUI5Timeout) {
* @param {[sap.ui.core.Control]} aControls
* @return {Array} Object
*/
window.wdi5.createControlIdMap = (aControls) => {
window.wdi5.createControlIdMap = (aControls, controlType = "") => {
// the array of UI5 controls need to be mapped (remove circular reference)

return aControls.map((element) => {
// just use the absolute ID of the control
let item = {
id: element.getId()
if (controlType === "sap.m.ComboBox" && element.data("InputWithSuggestionsListItem")) {
return {
id: element.data("InputWithSuggestionsListItem").getId()
dominikfeininger marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
return {
id: element.getId()
}
}
return item
})
}

Expand Down
11 changes: 11 additions & 0 deletions examples/ui5-js-app/webapp/controller/Main.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ sap.ui.define(

let testModel = new JSONModel(jData)
this.getView().setModel(testModel, "testModel")

this.initCombobox()
},

initCombobox: function () {
// set explored app's demo model on this sample
var oModel = new JSONModel()
oModel.loadData(
"https://raw.githubusercontent.com/SAP/openui5/master/src/sap.ui.documentation/test/sap/ui/documentation/sdk/countriesExtendedCollection.json"
)
this.getView().setModel(oModel, "Countries")
},

navFwd() {
Expand Down
28 changes: 28 additions & 0 deletions examples/ui5-js-app/webapp/test/e2e/basic.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
const Main = require("./pageObjects/Main")

const oComboboxSelector = {
// forceSelect: true,
controlType: "sap.m.ComboBox",
selector: {
interaction: "root",
id: "combobox",
viewName: "test.Sample.view.Main"
}
}

describe("ui5 basic", () => {
before(async () => {
await Main.open()
Expand Down Expand Up @@ -48,4 +58,22 @@ describe("ui5 basic", () => {
expect(invalidControl1).toContain("ERROR")
expect(invalidControl2).toContain("ERROR")
})

// #121
it("get combobox control items", async () => {
dominikfeininger marked this conversation as resolved.
Show resolved Hide resolved
const combobox = await browser.asControl(oComboboxSelector)
// get items (not with every ui5 control) works as expected
dominikfeininger marked this conversation as resolved.
Show resolved Hide resolved
const items = await combobox.getItems(true)
expect(items.length).toEqual(70)
})

// #121
it.only("get combobox control items (deep)", async () => {
dominikfeininger marked this conversation as resolved.
Show resolved Hide resolved
dominikfeininger marked this conversation as resolved.
Show resolved Hide resolved
const combobox = await browser.asControl(oComboboxSelector)

await combobox.open()
// get items (not with every ui5 control) works as expected
dominikfeininger marked this conversation as resolved.
Show resolved Hide resolved
const items = await combobox.getItems(4)
expect(await items.getTitle()).toEqual("Bahrain")
})
})
9 changes: 9 additions & 0 deletions examples/ui5-js-app/webapp/view/Main.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@
<Button text="open Dialog"
press="openDialog"
id="openDialogButton" />
<Label text="Country Combobox"/>
<ComboBox
id="combobox"
items="{
path: 'Countries>/CountriesCollection',
sorter: { path: 'text' }
}">
<core:Item key="{Countries>key}" text="{Countries>text}" />
</ComboBox>
</VBox>
</content>
</Page>
Expand Down
32 changes: 30 additions & 2 deletions src/lib/wdi5-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class WDI5Control {
_generatedUI5Methods: [] | string = null
_initialisation = false
_forceSelect = false
_controlType = ""

constructor() {
return this
Expand Down Expand Up @@ -95,6 +96,32 @@ export class WDI5Control {
return await this._getAggregation(name)
}

/**
* @param {Boolean | Int} true for flat items aggregation, Int to retrive a single item of the aggregation
dominikfeininger marked this conversation as resolved.
Show resolved Hide resolved
*/
async getComboboxItems(oParam) {
// first open the combobox, otherwise the items are not in DOM
await this.open()

// const _items = await this.getAggregation("items")
const _items = await this.executeControlMethod("getItems", this._webElement)
if (typeof oParam === "boolean" && oParam === false) {
// boolean
const returnItems = []
// assume the current control got a getItems method attached by the fluent UI5 api
_items.forEach(async (item) => {
dominikfeininger marked this conversation as resolved.
Show resolved Hide resolved
const itemId = await item.data("InputWithSuggestionsListItem").getId()
returnItems.push(await browser.asControl({ selector: { id: itemId } }))
})
return returnItems
} else if (String(oParam) && typeof oParam === "number") {
// assume the current control got a getItems method attached by the fluent UI5 api
// get the real id
const itemId = await _items[oParam].data("InputWithSuggestionsListItem").getId()
return await browser.asControl({ selector: { id: itemId } })
}
}

/**
* enters a text into a UI5 control
* @param text
Expand Down Expand Up @@ -244,7 +271,7 @@ export class WDI5Control {
// returns the array of [0: "status", 1: result]

// regular browser-time execution of UI5 control method
const result = await clientSide_executeControlMethod(webElement, methodName, args)
const result = await clientSide_executeControlMethod(webElement, methodName, this._controlType, args)

// create logging
this.writeResultLog(result, methodName)
Expand Down Expand Up @@ -301,7 +328,7 @@ export class WDI5Control {
if (util.types.isProxy(webElement)) {
webElement = await Promise.resolve(webElement)
}
const result = await clientSide_getAggregation(webElement, aggregationName)
const result = await clientSide_getAggregation(webElement, aggregationName, this._controlType)

this.writeResultLog(result, "_getAggregation()")

Expand Down Expand Up @@ -355,6 +382,7 @@ export class WDI5Control {
* @return {[WebdriverIO.Element | String, [aProtoFunctions]]} UI5 control or error message, array of function names of this control
*/
private async getControl(controlSelector = this._controlSelector) {
this._controlType = controlSelector.controlType
dominikfeininger marked this conversation as resolved.
Show resolved Hide resolved
// check whether we have a "by id regex" locator request
if (controlSelector.selector.id && typeof controlSelector.selector.id === "object") {
// make it a string for serializing into browser-scope and
Expand Down