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

0.9.10: Not possible to catch browser.asControl() exception #318

Closed sebage closed 2 years ago

sebage commented 2 years ago

Hi,

as it is not possible with WDI5's browser.asControl() to check if a element does not exist on the screen, we up to now catched the thrown exception (see issue https://github.com/ui5-community/wdi5/issues/139).

Since version 0.9.10 this does not work anymore, as the catch block is not reached anymore:

    async expectNotToExist(oControlSelector) {
        try {
            var oControl = await browser.asControl(oControlSelector);
        } catch (e) {
            await expect(e.message).toEqual(expect.stringContaining("[wdi5]call of _getControl() failed because of: Error: No DOM element found using the control selector"));
            return;
        }
        //This expect needs to be outside of try-catch, to avoid that a exception of this .not.toExist() call is feteched as well.
        await expect(await oControl.getWebElement()).not.toExist();
    }

The yellow part in the attached screenshot was not print out in earlier WDI5 versions (with log level error): error

vobu commented 2 years ago

thanks for providing the code that we can use as a minimal reproducible example 👍 we‘ll look into this and report back and meanwhile just fyi: there was a major improvement in detailed error messages coming in with https://github.com/ui5-community/wdi5/commit/f7b318263fe9eebc87ede950feeece51b865dec2 hopefully we didn‘t break exceptions with that 😐👀

Siolto commented 2 years ago

Hi @sebage,

bug confirmed! Thanks for reporting that issue.

The error with the message control could not be found shouldn't be thrown like that. There should be an additional entry in the log like Can not call "getWebElement()", because control could not be found.

btw: to check that an element is not visible on the screen/does not exist you could als try to use a native wdi5 function called isInitialized(). This will be false when no DOM element was found. Your check could look something like that:

const oControl = await browser.asControl(controlSelector)
expect(await oControl.isInitialized()).toBeFalsy()