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

[Question] Is it possible to assert a UI5 control is invisible #105

Closed cwang1221 closed 2 years ago

cwang1221 commented 2 years ago

Hi Experts,

I'm new to WDI5, I was trying to assert a UI5 control is not visible on UI, but it didn't work.

var input= browser.asControl({
            selector: {
                id: "myInput",
                viewName: "myView",
                visible: false
            }
        });

        expect(input.getVisible()).toBe(false);

It seems that I can only assert visible controls, but not invisible ones?

Thank you and best regards.

vobu commented 2 years ago

interesting observation. AFAIK, we don't have a testcase for invisible elements yet. is your input actually in the DOM, hidden by css? or not rendered yet? can you provide more code-context as to what control etc pp please?

cwang1221 commented 2 years ago

Thank you @vobu ! We just used the standard UI5 function myInput.setVisible(false) to hide it. This means:

  1. UI5 adds a hidden DOM element for this control: image
  2. But the DOM element is not an input. UI5 does not just add an input DOM and hide it. A visible input DOM should look like: image

Since WDI5's selector is very similar to OPA5's, I also tried visible: false, which means "I want to locate the control no matter if it's visible or not" in OPA5. But it didn't work. image

The test scenario is, I want to assert the input is successfully hidden with myInput.setVisible(false). I know this should be done with OPA5 test. But I just want to see if WDI5 can achieve it.

Thank you!

vobu commented 2 years ago

thanks for providing the details! I got curious and validated your use case → result: doesn't work, meaning wdi5 currently doesn't support the visible: false property of sap.ui.test.Opa5#waitFor 😒

But I've added this as a feature request 😸: #106

FWIW, you can still locate the DOM equivalent of the (unrendered) UI5 control by utilizing wdio's native feature (that wdi5 is built on): UI5 control:

<!-- sap.m namespace -->
<Input id="visibleInputField"
value="bla"
visible="false" />
const id = 'visibleInputField';
// wdio-native selector
const wdioInput = browser.$(`[id$="${id}"]`); // ID ends with "visibleInputField"
expect(wdioInput.getProperty('id')).toContain('sap-ui-invisible');
cwang1221 commented 2 years ago

Thank you @vobu ! It's really great to see improvements in wdi5!