0

I'm jQuery from Cypress in writing a Cypress automated test. My objective is to do a search with no search criteria (we have several attributes that we can search on), then grab some attributes from the search results and do a search using some of those attributes. The second search should only return records that meet the search criteria of the second search.

Here's the code that attempts to do this:

            cy.wait(5000);

            let row = 0;
            if (portRejectsResultSummary.cellExists('sequence-row-' + row)) {
                do {
                    //loop until we find a row that has the instrument id set
                    if (portRejectsResultSummary.cellExists('instrumentIds-row-' + row)) {
                        let expectedInstrumentId = portRejectsResultSummary.getCell('instrumentIds-row-' + row).text();
                        portRejectsSearchFilters.instrumentIdInputField(expectedInstrumentId);
                        portRejectsSearchFilters.searchButton();
                        cy.wait(5000);

                        for (let i=0;i<100 && portRejectsResultSummary.cellExists('sequence-row-' + i);i++) {
                            portRejectsResultSummary.verifySummaryInstrumentIdCellData(i, expectedInstrumentId);
                        }
                        return;
                    }
                    row++;
                } while (row < 100 && portRejectsResultSummary.cellExists('sequence-row-' + row));
            }

The Cypress and Cypress.$ calls happen from those cellExists and verifySummaryInstrumentIdCellData methods. The problem is that in that inner for loop, cellExists continues to return true, even if there are no more search results from the second search, because jQuery is still seeing the values from the first search, which returned all records.

Any thoughts on why jQuery doesn't have access to the latest dom? This is a one page web application.

  • Surely there is an API call you can intercept and wait on or something else you can do instead of a hardcoded wait. – jjhelguero Aug 13 '22 at 02:54
  • are the results of the first search not in the dom as it sounds like its finding the items because they are present but perhaps matching on the wrong elements ? if the elements are not in the dom not sure how jquery could find them but if that somehow is the case might be worth checking out https://stackoverflow.com/questions/2844565/is-there-a-javascript-jquery-dom-change-listener but I suspect that the issue is with the inner loop finding something in the dom that is there, hard to tell with out more info sorry – Patrick Hume Aug 13 '22 at 03:45
  • @jjhelguero perhaps.......but I'm not a cypress (or a UI) expert :( – Victor Rodriguez Aug 15 '22 at 18:17
  • In open mode you can check your test steps and see some steps that are grey for any calls made by your app. They will typically be POST or GET calls. https://cypress.tips/search is a good resource for cypress. – jjhelguero Aug 15 '22 at 21:34

0 Answers0