ui5-community / wdi5

official UI5 end-to-end test framework for UI5 web-apps. wdi5 = Webdriver.IO + UI5 Test API
https://ui5-community.github.io/wdi5/
Apache License 2.0
102 stars 43 forks source link

Problem getting selected keys from MultiComboBox-control #160

Closed ph-alsvik closed 2 years ago

ph-alsvik commented 2 years ago

Hello folks!

So I have an app with a MultiComboBox control with string-valued keys. I've written a simple test in wdi5 which gets this control and checks if a certain key is preset. The test looks like this:

it("validates that 'temperature' sensor is pre-selected", async () => {
        const oSelector = {
            forceSelect: true,
            timeout: 15000,
            selector: {
                interaction: "root",
                controlType: "sap.m.MultiComboBox",
                id: "sensor-select",
                viewName: "app.view.main"
            }
        };
        const control = await browser.asControl(oSelector);
        const selectedKeys = await control.getSelectedKeys();
        expect(selectedKeys[0]).toEqual("temperature");
});

I get the control without issue, but when calling the getSelectedKeys-method on it, it fails with a timeout-error.

Inspecting the console in the browser reveals that there is a type error in the code running in the client:

Uncaught (in promise) TypeError: element.getId is not a function
    at eval (eval at executeAsyncScript (index.html:552:26), <anonymous>:228:45)
    at Array.map (<anonymous>)
    at Object.window.wdi5.createControlIdMap (eval at executeAsyncScript (index.html:552:26), <anonymous>:225:42)
    at eval (eval at executeAsyncScript (index.html:552:26), <anonymous>:22:42)
    at v (_promiseWaiter.js:6:2327)

Have I written the test wrong or is this a bug?

If something is unclear with this issue, just let me know.

Thank you!

vobu commented 2 years ago

hi! all looking good on your code (except the timeout selector option that doesn‘t exist (https://js-soft.github.io/wdi5/#/configuration?id=wdi5) 😝) we still have an issue with ComboBox → see #121 so it‘s on our todo, but not yet done ok for you to track this in #121 and closing this?

ph-alsvik commented 2 years ago

Thanks for your reply! Yes, I'll close this issue. Just want to add one final thing:

I did a little investigation myself. I think the issue is related to this part in executeControlMethod.js:

if (Array.isArray(result)) {
    // 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)
    done(["success", result, "aggregation"])
}

It seems that when the returned value of one of the get$Shorthand-methods is an array, wdi5 assumes its an array of objects, but in case of getSelectedKeys its an array of strings.

Perhaps you already know, but sharing my knowledge just in case 😃

vobu commented 2 years ago

Thanks for your reply! Yes, I'll close this issue. Just want to add one final thing:

I did a little investigation myself. I think the issue is related to this part in executeControlMethod.js:

if (Array.isArray(result)) {
    // 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)
    done(["success", result, "aggregation"])
}

It seems that when the returned value of one of the get$Shorthand-methods is an array, wdi5 assumes its an array of objects, but in case of getSelectedKeys its an array of strings.

Perhaps you already know, but sharing my knowledge just in case 😃

excellent, thanks for the hint! now that you're already that close to the root cause....how about giving a fix and a Pull Request a shot?!? 🚀

i'm just writing the dev time setup/onboarding doc (see #163), but here's the gist:

# you need npm 7+ → we're using npm's workspaces feature
$> npm --version
# will also install all deps in workspaces + setup pre-commit hooks
$> npm i 
# build entire proj once
$> npm run build
# turn on build watcher
$> npm run build:watch

Then to work on a test: ...in terminal 1:

# start the sample js app
$> npm run _startApp:js

...in terminal 2:

# run a single test with wdi5/wdio
### runs the "test:websever" script from /examples/ui5-js-app/package.json
### in workspace "examples/ui5-js-app"
### but only any test file in /examples/ui5-js-app/webapp/test/e2e/**/* that
### matches "basic" in the filename
### and run in watch mode (browser stays open, test reruns when file changes)
### for true TDD 
$> npm run test:webserver -w examples/ui5-js-app -- --spec basic --watch
ph-alsvik commented 2 years ago

Sure! I'll try to fix it 😄