From 881e247244d8cd0573eef4303311cd41507c0f6d Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 14 Dec 2023 14:46:02 +0530 Subject: [PATCH] fix flaky test (#6864) --- 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 + } + }); }); } }