From 7e2cdb55a75382607a2eea111e82e5c9d67bb047 Mon Sep 17 00:00:00 2001 From: lgestc Date: Thu, 14 Sep 2023 19:03:02 +0200 Subject: [PATCH] [Security Solution] Fix flaky hover actions test --- .../e2e/explore/network/hover_actions.cy.ts | 17 +++++------- .../cypress/tasks/network/flows.ts | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/explore/network/hover_actions.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/explore/network/hover_actions.cy.ts index e03e70dcd8535..4350d2397c778 100644 --- a/x-pack/test/security_solution_cypress/cypress/e2e/explore/network/hover_actions.cy.ts +++ b/x-pack/test/security_solution_cypress/cypress/e2e/explore/network/hover_actions.cy.ts @@ -18,15 +18,14 @@ import { clickOnFilterIn, clickOnFilterOut, clickOnShowTopN, - mouseoverOnToOverflowItem, - openHoverActions, + withHoverActionsReady, } from '../../../tasks/network/flows'; import { openTimelineUsingToggle } from '../../../tasks/security_main'; const testDomain = 'myTest'; // tracked by https://github.com/elastic/kibana/issues/161874 -describe.skip('Hover actions', { tags: ['@ess', '@serverless'] }, () => { +describe('Hover actions', { tags: ['@ess', '@serverless'] }, () => { const onBeforeLoadCallback = (win: Cypress.AUTWindow) => { // avoid cypress being held by windows prompt and timeout cy.stub(win, 'prompt').returns(true); @@ -43,18 +42,16 @@ describe.skip('Hover actions', { tags: ['@ess', '@serverless'] }, () => { beforeEach(() => { login(); visit(NETWORK_URL, { visitOptions: { onBeforeLoad: onBeforeLoadCallback } }); - openHoverActions(); - mouseoverOnToOverflowItem(); }); it('Adds global filter - filter in', () => { - clickOnFilterIn(); + withHoverActionsReady(clickOnFilterIn); cy.get(GLOBAL_SEARCH_BAR_FILTER_ITEM).should('have.text', `destination.domain: ${testDomain}`); }); it('Adds global filter - filter out', () => { - clickOnFilterOut(); + withHoverActionsReady(clickOnFilterOut); cy.get(GLOBAL_SEARCH_BAR_FILTER_ITEM).should( 'contains.text', `NOT destination.domain: ${testDomain}` @@ -63,7 +60,7 @@ describe.skip('Hover actions', { tags: ['@ess', '@serverless'] }, () => { it('Adds to timeline', () => { const DATA_PROVIDER_ITEM_NUMBER = 1; - clickOnAddToTimeline(); + withHoverActionsReady(clickOnAddToTimeline); openTimelineUsingToggle(); cy.get(DATA_PROVIDERS).should('have.length', DATA_PROVIDER_ITEM_NUMBER); @@ -71,14 +68,14 @@ describe.skip('Hover actions', { tags: ['@ess', '@serverless'] }, () => { }); it('Show topN', () => { - clickOnShowTopN(); + withHoverActionsReady(clickOnShowTopN); cy.get(TOP_N_CONTAINER).should('exist').should('contain.text', 'Top destination.domain'); }); it('Copy value', () => { cy.document().then((doc) => cy.spy(doc, 'execCommand').as('execCommand')); - clickOnCopyValue(); + withHoverActionsReady(clickOnCopyValue); cy.get('@execCommand').should('have.been.calledOnceWith', 'copy'); }); diff --git a/x-pack/test/security_solution_cypress/cypress/tasks/network/flows.ts b/x-pack/test/security_solution_cypress/cypress/tasks/network/flows.ts index b9febb6a39381..d6d96c26de30c 100644 --- a/x-pack/test/security_solution_cypress/cypress/tasks/network/flows.ts +++ b/x-pack/test/security_solution_cypress/cypress/tasks/network/flows.ts @@ -29,6 +29,32 @@ export const mouseoverOnToOverflowItem = () => { cy.get(OVERFLOW_ITEM).first().realHover(); }; +/** + * What is crucial here is that we need to verify whether or not the actions portal element is visible, + * and only then we can perform the action. This is done immediately before any action is performed on the actions button itself, + * and if for some reason the actions portal element is not visible, we will try to hover over the actions activator element again. + * @param action + * @param maxTries + */ +export function withHoverActionsReady(action: () => void, maxTries = 10) { + // NOTE: not sure if this is precise enough, but it seems to work + const actionsButtonInPortal = '[data-euiportal="true"] button[data-test-subj*="cellActions"]'; + + // Check if actions portal element is visible + cy.get('body').then(($body) => { + if ($body.find(actionsButtonInPortal).length > 0) { + cy.get(actionsButtonInPortal).should('be.visible'); + action(); + } else if (maxTries <= 0) { + throw new Error(`Max tries reached. The element ${actionsButtonInPortal} is not visible.`); + } else { + openHoverActions(); + mouseoverOnToOverflowItem(); + withHoverActionsReady(action, maxTries - 1); + } + }); +} + export const clickOnFilterIn = () => { cy.get(FILTER_IN).first().click(); };