From 2b7c488d3509f772ac673c7d0fab9563b1f2c10c Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 14 Dec 2023 14:37:41 +0530 Subject: [PATCH] fix flaky test --- cypress/pageobject/Users/UserSearch.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cypress/pageobject/Users/UserSearch.ts b/cypress/pageobject/Users/UserSearch.ts index 4956532277f..12ac64c51b3 100644 --- a/cypress/pageobject/Users/UserSearch.ts +++ b/cypress/pageobject/Users/UserSearch.ts @@ -104,9 +104,25 @@ export class UserPage { cy.url().should("include", `page=${pageNumber}`); } - verifyMultipleBadgesWithSameId(expectedContents: string[]) { - cy.get("#user-view-name").each((el, index) => { - expect(el.text().trim()).to.equal(expectedContents[index]); + verifyMultipleBadgesWithSameId(alreadylinkedusersviews: string[]) { + cy.get("#user-view-name").then(($elements) => { + const userViews = $elements + .map((_, el) => Cypress.$(el).text().trim()) + .get(); + let foundMatches = 0; + + alreadylinkedusersviews.forEach((expectedContent) => { + const index = userViews.findIndex((actualContent) => + actualContent.includes(expectedContent) + ); + if (index !== -1) { + userViews.splice(index, 1); // Remove the matched element + foundMatches++; + } + if (foundMatches === alreadylinkedusersviews.length) { + return false; // Break the loop if all matches are found + } + }); }); } }