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

Control() failed because of: Error: waitAsync is already running and cannot be called again at this moment #452

Closed abdelhaknezzari closed 1 year ago

abdelhaknezzari commented 1 year ago

Hello, Describe the bug We are getting error: [wdi5] call of _getControl() failed because of: Error: waitAsync is already running and cannot be called again at this moment [wdi5] error retrieving control: columnListItemId-__clone2 [wdi5] _asControl() needed 7.740290999412537 for columnListItemId-__clone2

After calling: const tab = await browser.asControl({ forceSelect: true, selector: { id: "application-feature-display-component---FeatureList--featureListTableId", interaction: "root" // <-- hooray! }}); const items =await tab.getAggregation("items");

the first statement await browser.asControl is working fine, The error is coming from the last statement of getting the items, and we have already a test scenario that is clicking on buttons which working fine, we have a problem only in getting the items of a list.

To Reproduce You need to run the scenario we have, it will be not easy to share

Expected behavior We are expecting the to get the items of table without errors, because we need for every item to extract some information about the rows , like text, statuses, .., this is not working: const items =await tab.getAggregation("items");

    for( let i=0; i < items.length ; i++ ) {
        const cells = await items[i].getAggregation('cells');
        const titleItems = await cells[0].getItems();
        const title = await titleItems[0].getTitle();

        // const title = await (await(cells[0].getItems())[0].getTitle());
        // const status = await (await (cells[1].getItems())[0].getText());
        // const priority = await (await (cells[2].getItems())[0].getText());
        // const priorityIcon= await (await (cells[2].getItems())[0].getIcon());
        // const priorityTooltip= await (await (cells[2].getItems())[0].getTooltip());
        // const priorityColor= await (await (cells[2].getItems())[0].getState());
    }

Logs/Console Output [wdi5] call of _getControl() failed because of: Error: waitAsync is already running and cannot be called again at this moment [wdi5] error retrieving control: columnListItemId-__clone2 [wdi5] _asControl() needed 7.740290999412537 for columnListItemId-__clone2

Screenshots

Screenshot 2023-04-13 at 11 52 22

Runtime Env (please complete the following information): "@ui5/cli": "3.0.5", "@wdio/cli": "7.20.9", "@wdio/cucumber-framework": "7.20.8", "@wdio/devtools-service": "7.20.9", "@wdio/junit-reporter": "7.20.7", "@wdio/local-runner": "7.20.9", "@wdio/sauce-service": "7.20.9", "@wdio/spec-reporter": "7.20.8", "wdio-cucumber-reporter": "0.0.2", "wdio-cucumberjs-json-reporter": "4.4.3", "wdio-intercept-service": "4.2.2", "wdio-ui5-service": "^1.3.2", "wdi5": "^0.7.0",

Chrome Version 112.0.5615.49 (Official Build) (arm64)

node --version v16.19.1

MacOs:13.3.1 (22E261)

Additional context We are also using OPAE2E also,

Screenshot 2023-04-13 at 11 59 55

services: ['devtools', 'ui5', 'intercept', [ParallelTestService, { rootDir: path.resolve(__dirname), backendPath: backendPath, dwcLocalConfigFile: './dwc-local-config.json', maxParallelInstances: maxParallelInstances, maxWaitForInstancesToStart: 200000, skipInstrument: skipInstrument, profile: 'default' }], [pipelineUtilities.wdioAnalysePR, { repositoryName: "CALMBuild/cdm-features-ui" }]],

wdio.config: .... wdi5: { screenshotPath: require("path").join("some", "dir", "for", "screenshots"), // [optional] {string}, default: "" screenshotsDisabled: false, // [optional] {boolean}, default: false; if set to true, screenshots won't be taken and not written to file system logLevel: "verbose", // [optional] error | verbose | silent, default: "error" skipInjectUI5OnStart: true, // [optional] {boolean}, default: false; true when UI5 is not on the start page, you need to later call .injectUI5() manually waitForUI5Timeout: 15000 // [optional] {number}, default: 15000; maximum waiting time in milliseconds while checking for UI5 availability },

vobu commented 1 year ago

a for loop does not wait for an asynchronous operation to complete. so what you're seeing are the side effects of multiple async ops running in parallel. try converting your for loop to a for-of: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of

abdelhaknezzari commented 1 year ago

Hi @vobu , the error: [wdi5] call of _getControl() failed because of: Error: waitAsync is already running and cannot be called again at this moment [wdi5] error retrieving control: columnListItemId-__clone2 [wdi5] _asControl() needed 7.740290999412537 for columnListItemId-__clone2

is coming from statment: const items =await tab.getAggregation("items");

if I continue the debugging until the for loop: for (const item of items) { const cells = await item.getAggregation('cells'); const titleItems = await cells[0].getItems(); const title = await titleItems[0].getTitle(); }

it will give another error,

regards,

vobu commented 1 year ago

of what type is the table that you're trying to call getAggregation("items") on? sap.ui.table.Table? b/c then it would be getAggregation("rows"). getAggregation("items") is for a sap.m.Table.

abdelhaknezzari commented 1 year ago

yes I confirm it is sap.ui.table.Table:

Screenshot 2023-04-17 at 09 27 49

the error is happening as well with : getAggregation("items") and getItems() methods of "sap.m.Table"

vobu commented 1 year ago

you're saying it is a sap.ui.table.Table, yet your screenshot shows a sap.m.Table - which one is it now? 😄 and what selector does the Testrecorder show it you switch the "select a dialect" to wdi5?

abdelhaknezzari commented 1 year ago

it is sap.m.Table (import Table from 'sap/m/Table';)

the selector is working fine: const tab = await browser.asControl({ forceSelect: true, selector: { id: "application-feature-display-component---FeatureList--featureListTableId", interaction: "root" }});

vobu commented 1 year ago

hm, all i can say about this from the distance is that we're extensively using tables/lists as well in our own tests, e.g. https://github.com/ui5-community/wdi5/blob/main/examples/ui5-js-app/webapp/test/e2e/aggregation.test.js https://github.com/ui5-community/wdi5/blob/f45a5b67415caab902de3883fedc132908c9b7bc/examples/ui5-js-app/webapp/test/e2e/fluent-async-api.test.js#L35

does .getItems(0) work on your sap.m.Table?

abdelhaknezzari commented 1 year ago

const items = [await tab.getItems(0) ]; is working without errors

but getting errors afterwards with the following code: for (const item of items) { const cells = await item.getAggregation('cells'); const titleItems = await cells[0].getItems(); const title = await titleItems[0].getTitle(); }

vobu commented 1 year ago

Then I'd suggest you try to debug each call as described in https://ui5-community.github.io/wdi5/#/debugging and check where the actual error occurs!

abdelhaknezzari commented 1 year ago

do you mean debug WDI5 library? if yes, do you have suggestion where I can put the debugger statement before it is loaded to the browser,

Screenshot 2023-04-17 at 11 56 26
abdelhaknezzari commented 1 year ago

Hi @vobu not sure if you get the notification for my last question, as the error is coming deep from WDI5, I need some insight where we can debug in the library, especially where the .sap.m.table code is located, to undestand what's going on

philippthiele commented 1 year ago

image The error originates from the _autoWaiterAsync from sap.test package. What does work is calling: await tab.getItems(0) await tab.getItems(1) await tab.getItems(2)

What does not work is await tab.getItems()

It seems wdi5 is triggering retrieving all items simultaneously from the browser, this function here is executed for each item before they are resolved: image

This seems to be prevented by the before if statement "if (bWaitStarted)": https://github.com/SAP/openui5/blob/251005d26646ef28e635e40819c94f14b433784a/src/sap.ui.core/src/sap/ui/test/autowaiter/_autoWaiterAsync.js#L37

vobu commented 1 year ago

woah, thanks for diving deep here @philippthiele 🤿 ! from the wdi5 perspective, we're just reusing what the RecordReplay API offers - e.g. no special handling for retreiving aggregations from a UI5 control. i'm not sure how to proceed here @abdelhaknezzari as we're at the point where you'd most likely need specific counseling on source- and test-code whom you can't seem to share publicly. Mind continuing this via e-mail? → see my profile for e-mail-address

philippthiele commented 1 year ago

@vobu I have created a potential fix here, that is working for me: https://github.com/ui5-community/wdi5/pull/455 Maybe you can assess whether this is the right way to fix the issue or it might spark some idea how to do it correctly otherwise.

vobu commented 1 year ago

providing a PR: that's the spirit, yesss 🙌 let's continue working in there!