From ab2c497358292aa73951fe1591278f78e9de2ae3 Mon Sep 17 00:00:00 2001 From: Kohinoor Chatterjee Date: Thu, 16 Nov 2023 17:08:55 -0800 Subject: [PATCH] [flaky test]solution for aliases.js (#920) * wait added for api call before cy.contains Signed-off-by: kohinoor98 * adding an arbitrary wait for aliases.js Signed-off-by: kohinoor98 * optimised beforeEach and increased wait time Signed-off-by: kohinoor98 * increasing timeout and custom impl for retry Signed-off-by: kohinoor98 * revert retry logic Signed-off-by: kohinoor98 * added log for apiCaller and removed wait for osd Signed-off-by: kohinoor98 --------- Signed-off-by: kohinoor98 --- .../aliases.js | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js index 55b0dfe72..97e84cb6e 100644 --- a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js +++ b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js @@ -26,11 +26,32 @@ describe("Aliases", () => { }); beforeEach(() => { + // Intercept the specific POST request + cy.intercept("POST", "/api/ism/apiCaller", (req) => { + if (req.body.data && req.body.data.name === "**" && req.body.data.s === "alias:desc" && req.body.endpoint === "cat.aliases") { + req.alias = "apiCaller"; // Assign an alias directly if the condition is met + } + }); + // Visit ISM OSD cy.visit(`${BASE_PATH}/app/${IM_PLUGIN_NAME}#/aliases`); - // Common text to wait for to confirm page loaded, give up to 60 seconds for initial load - cy.contains("Rows per page", { timeout: 60000 }); + // Wait for 120 seconds for OSD to start. + // eslint-disable-next-line cypress/no-unnecessary-waiting + // cy.wait(120000); + + const startTime = new Date().getTime(); + + // Wait for the API call to complete + cy.wait("@apiCaller", { timeout: 240000 }).then(() => { + // Log the calculated duration + const endTime = new Date().getTime(); + const duration = endTime - startTime; // Duration in milliseconds + cy.log(`@apiCaller completed in ${duration} milliseconds`); + }); + + // Common text to wait for to confirm page loaded, give up to 120 seconds for initial load + cy.contains("Rows per page", { timeout: 120000 }).should("be.visible"); }); describe("can be searched / sorted / paginated", () => {