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

getSelectedItem() doesn't return object correctly #291

Closed soraY27 closed 2 years ago

soraY27 commented 2 years ago

Describe the bug While writing the tests it was noticed that the method "getSelectedItem()" of the control "sap.m.Select" (https://sapui5.hana.ondemand.com/#/api/sap.m.Select%23methods/getSelectedItem) does not return a WDI5Control object. Instead, the object is output as a string on the console and returned as a simple object (Not of the type WDI5Control). This makes it impossible to continue working with the requested control.

To Reproduce Steps to reproduce the behavior:

  1. First you need a simple SAP UI5 application with a sap.m.Select control
  2. Then you have to create the required test files for WDI5 for this application.
  3. My used code for the tests is further described below.
  4. When the test environment has been created, you now start the WDI5 tests
  5. During the test a very long string is output to the console (Console output is included as an appendix) and the tests would fail if you continue to work with this object
  6. See error and the object is output to the console as string

Expected behavior The object is not output to the console and is instead stored as an WDI5Control object in a variable.

Logs/Console Output Output.txt

const identifier = {
            forceSelect: true,
            selector: {
                interaction: "root",
                controlType: "sap.m.Select",
                viewName: "NameSpace.view.Detail",
                labelFor: {
                    text: "LabelForSelect"
                }
            }
}

const checkSelect = async () => {
    // Returns WDI5Control object 
    const location = await browser.asControl(identifier);

    // Returns object (Inside Output.txt)
    const locationSelected = await location.getSelectedItem();

    // This test will fail, because locationSelected is missing the function getText()
    expect(await locationSelected.getText()).toEqual("Text of selected item");
}

describe("Tests for detail view", () => {
    it("should have select item 'Text of selected item', checkSelect);
});

Screenshots ConsoleError

Runtime Env (please complete the following information):

vobu commented 2 years ago

thanks for providing such a detailed error description and log! i just checked and indeed we don't have a sap.m.Select in our tests yet. let us get onto this, then we'll check back in here with the results.

vobu commented 2 years ago

bug confirmend, fix underway

vobu commented 2 years ago

please also note that due to the implementation of the sap.m.Select, you have to first interact with the dropdown before its' items appear in the DOM and are thus selectable. See the respective test for a code example: https://github.com/js-soft/wdi5/blob/10eae1d3fd07aa26d4335bafa290f142535c9e03/examples/ui5-js-app/webapp/test/e2e/locators-basic.test.js#L71-L80

soraY27 commented 2 years ago

Wow you guys are really fast! Thank you dear WDI5 team for the quick solution 🙏

the-docta commented 2 years ago

hmm. Just wondering: will select.open() work (be enough) if the select is disabled (enabled=false and/or editable=false)?

vobu commented 2 years ago

you'll need the select.open() only for getting to the items aggregation. for locating the select itself, browser.asControl(selector) is sufficient.

the-docta commented 2 years ago

getSelectedItem wasn't working before the patch (which is an aggregation, but an aggregation to a single item, visible while select is closed - but I have not the slightest idea whether the rendered HTML has enough information to describe that item object).

I'm not sure whether we ever need the getSelectedItem for a disabled select. but without getSelectedItem there is no way to find out, what is currently shown in the select control (what is visible to the user)

PS: I guess, using getSelectedKey should work if we know the key, which may be a "random" guid, though

PPS: select.setEnabled(true) + select.open() should work in combination, so probably not that big deal after all...