From a60804c88b25c8a963be9bb8dbba85790cbea03a Mon Sep 17 00:00:00 2001 From: asirvadAbrahamVarghese Date: Fri, 12 Sep 2025 09:34:36 +0530 Subject: [PATCH 1/3] Injecting API intercept & wait for tree-select into selectAccordionItem --- cypress/support/commands/explorer.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cypress/support/commands/explorer.js b/cypress/support/commands/explorer.js index acbe7adfa12..90952d737d3 100644 --- a/cypress/support/commands/explorer.js +++ b/cypress/support/commands/explorer.js @@ -75,8 +75,13 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => { const currentLiElement = Cypress.$(listItems[i]); // If it's the last label in the path, then that is the desired item to click if (isClickableNode) { - // Click the node corresponding to the last label in the given path and terminate - cy.wrap(currentLiElement).click(); + // Click the node corresponding to the last label in the given path, + // intercept & wait for the Tree-Select api and then terminate + cy.interceptApi({ + alias: 'treeSelectApi', + urlPattern: /\/[^\/]+\/tree_select\?id=.*&text=.*/, + triggerFn: () => cy.wrap(currentLiElement).click(), + }); return; } From 89a35cb511c250ee262a31d2663ab49e9d0fb68a Mon Sep 17 00:00:00 2001 From: asirvadAbrahamVarghese Date: Fri, 12 Sep 2025 09:35:38 +0530 Subject: [PATCH 2/3] Flagging TODOs --- cypress/support/commands/explorer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress/support/commands/explorer.js b/cypress/support/commands/explorer.js index 90952d737d3..932c93665ed 100644 --- a/cypress/support/commands/explorer.js +++ b/cypress/support/commands/explorer.js @@ -48,7 +48,7 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => { const isClickableNode = accordionPathIndex === accordionPath.length - 1; for (let i = searchStartIndex; i < listItems.length; i++) { - /* @RemoveLater: Remove logger once the command is confirmed to be stable */ + /* TODO: Remove logger once the command is confirmed to be stable */ Cypress.log({ name: 'selectAccordionItem', message: `Loop index: ${i} & Searching for label: ${accordionLabel}`, @@ -65,7 +65,7 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => { } if (isMatch) { - /* @RemoveLater: Remove logger once the command is confirmed to be stable */ + /* TODO: Remove logger once the command is confirmed to be stable */ Cypress.log({ name: 'selectAccordionItem', message: `Matched "${liText}" at index ${i}`, From d3de9c57b32e5dfa36decdb2f839ab7cf26bf4cd Mon Sep 17 00:00:00 2001 From: asirvadAbrahamVarghese Date: Fri, 12 Sep 2025 09:40:56 +0530 Subject: [PATCH 3/3] Remove explicit tree-select API waits in tests --- .../edit_collect_logs.cy.js | 14 ++--- .../ui/validate-intercept-api-command.cy.js | 51 +++++++------------ 2 files changed, 21 insertions(+), 44 deletions(-) diff --git a/cypress/e2e/ui/Settings/Application-Settings/edit_collect_logs.cy.js b/cypress/e2e/ui/Settings/Application-Settings/edit_collect_logs.cy.js index 0b726bb569f..29de70d213e 100644 --- a/cypress/e2e/ui/Settings/Application-Settings/edit_collect_logs.cy.js +++ b/cypress/e2e/ui/Settings/Application-Settings/edit_collect_logs.cy.js @@ -226,16 +226,10 @@ describe('Automate Collect logs Edit form operations', () => { describe('Settings > Application Settings > Diagnostics > Manage IQ Region > Zone > Collect logs > Edit', () => { beforeEach(() => { // Select "Zone:" accordion item - cy.interceptApi({ - alias: 'treeSelectApi', - urlPattern: - /ops\/tree_select\?id=.*&text=.*Zone.*Default.*Zone.*(current).*/, - triggerFn: () => - cy.selectAccordionItem([ - MANAGEIQ_REGION_ACCORDION_ITEM, - ZONE_ACCORDION_ITEM, - ]), - }); + cy.selectAccordionItem([ + MANAGEIQ_REGION_ACCORDION_ITEM, + ZONE_ACCORDION_ITEM, + ]); // Select collect logs tab and open edit form goToCollectLogsTabAndOpenEditForm(); }); diff --git a/cypress/e2e/ui/validate-intercept-api-command.cy.js b/cypress/e2e/ui/validate-intercept-api-command.cy.js index 1c09ef177e6..fc3264e4b13 100644 --- a/cypress/e2e/ui/validate-intercept-api-command.cy.js +++ b/cypress/e2e/ui/validate-intercept-api-command.cy.js @@ -10,18 +10,11 @@ describe('Validate intercept command', () => { it('Should register the alias, intercept, wait & validate response status code when an API is fired', () => { cy.accordion('Diagnostics'); - cy.interceptApi({ - alias: 'treeSelectApi', - urlPattern: /\/ops\/tree_select\?id=.*&text=.*/, - triggerFn: () => cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]), - onApiResponse: (interception) => { - expect(interception.response.statusCode).to.equal(200); - }, - }).then(() => { - // verifies that the alias is set and the request is intercepted & awaited - cy.getInterceptedApiAliases().then((interceptedAliasesObject) => { - expect(interceptedAliasesObject).to.have.property('post-treeSelectApi'); - }); + // Tree select api wait is handled from selectAccordionItem with alias 'treeSelectApi' + cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]); + // verifies that the alias is set and the request is intercepted & awaited + cy.getInterceptedApiAliases().then((interceptedAliasesObject) => { + expect(interceptedAliasesObject).to.have.property('post-treeSelectApi'); }); }); @@ -32,19 +25,14 @@ describe('Validate intercept command', () => { urlPattern: /\/ops\/accordion_select\?id=.*/, triggerFn: () => cy.accordion('Diagnostics'), }); - // second api with alias 'treeSelectApi' - cy.interceptApi({ - alias: 'treeSelectApi', - urlPattern: /\/ops\/tree_select\?id=.*&text=.*/, - triggerFn: () => cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]), - }).then(() => { - // verifies that both the aliases are set and the request is intercepted & awaited - cy.getInterceptedApiAliases().then((interceptedAliasesObject) => { - expect(interceptedAliasesObject).to.include.all.keys( - 'post-accordionSelectApi', - 'post-treeSelectApi' - ); - }); + // second api with alias 'treeSelectApi'(Tree select api wait is handled from selectAccordionItem with alias 'treeSelectApi') + cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]); + // verifies that both the aliases are set and the request is intercepted & awaited + cy.getInterceptedApiAliases().then((interceptedAliasesObject) => { + expect(interceptedAliasesObject).to.include.all.keys( + 'post-accordionSelectApi', + 'post-treeSelectApi' + ); }); }); @@ -59,15 +47,10 @@ describe('Validate intercept command', () => { expect(Object.keys(interceptedAliasesObject).length).to.equal(1); }); }); - // second first api with alias 'treeSelectApi' - cy.interceptApi({ - alias: 'treeSelectApi', - urlPattern: /\/ops\/tree_select\?id=.*&text=.*/, - triggerFn: () => cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]), - }).then(() => { - cy.getInterceptedApiAliases().then((interceptedAliasesObject) => { - expect(Object.keys(interceptedAliasesObject).length).to.equal(2); - }); + // second api with alias 'treeSelectApi'(Tree select api wait is handled from selectAccordionItem with alias 'treeSelectApi') + cy.selectAccordionItem([/^ManageIQ Region:/, /^Zone:/]); + cy.getInterceptedApiAliases().then((interceptedAliasesObject) => { + expect(Object.keys(interceptedAliasesObject).length).to.equal(2); }); // third api with a duplicate alias as above 'accordionSelectApi' cy.interceptApi({