From aae98fb21b0145291b76aa22c12a096fd78cc413 Mon Sep 17 00:00:00 2001 From: Mark Hopkin Date: Tue, 18 Jun 2024 14:27:26 +0100 Subject: [PATCH] [Entity Analytics] Flaky Cypress test fixes (#186081) ### Fix 1: Press refresh button after using date picker on dashboard Closes https://github.com/elastic/kibana/issues/183662 Closes https://github.com/elastic/kibana/issues/183635 Closes https://github.com/elastic/kibana/issues/183982 We shouldnt have to do this, but there is some condition where clicking apply gets the UI in a stuck state and I cant figure it out. ### Fix 2: Use more specific selector for search bar on risk score preview page Closes https://github.com/elastic/kibana/issues/184133 We were using a generic selector `[data-test-subj="unifiedQueryInput"] textarea` which was bringing back two elements sometimes (no idea why), I have given the box its own dedicated selector to hopefully prevent this from happening --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit c34bb46c8aeb59dca0c92132dd34d2d9fca68728) --- .../components/risk_score_preview_section.tsx | 1 + .../dashboards/entity_analytics/new_risk_score.cy.ts | 2 ++ .../entity_analytics/entity_analytics_management_page.cy.ts | 6 +++--- .../cypress/screens/entity_analytics_management.ts | 3 +++ .../cypress/tasks/entity_analytics.ts | 6 +++--- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/risk_score_preview_section.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/risk_score_preview_section.tsx index c927a12f48a64..695143fe7a4a3 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/risk_score_preview_section.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/risk_score_preview_section.tsx @@ -227,6 +227,7 @@ const RiskEnginePreview = () => { showDatePicker={true} displayStyle={'inPage'} submitButtonStyle={'iconOnly'} + dataTestSubj="risk-score-preview-search-bar-input" /> )} diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/dashboards/entity_analytics/new_risk_score.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/dashboards/entity_analytics/new_risk_score.cy.ts index 894248f9ff716..da59afaec941c 100644 --- a/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/dashboards/entity_analytics/new_risk_score.cy.ts +++ b/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/dashboards/entity_analytics/new_risk_score.cy.ts @@ -103,6 +103,7 @@ describe('Entity Analytics Dashboard', { tags: ['@ess', '@serverless'] }, () => describe('With host risk data', () => { before(() => { + cy.task('esArchiverUnload', { archiveName: 'risk_scores_new' }); cy.task('esArchiverLoad', { archiveName: 'risk_scores_new' }); }); @@ -145,6 +146,7 @@ describe('Entity Analytics Dashboard', { tags: ['@ess', '@serverless'] }, () => describe('With alerts data', () => { before(() => { + deleteAlertsAndRules(); createRule(getNewRule()); }); diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/entity_analytics_management_page.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/entity_analytics_management_page.cy.ts index f23480e52d0d1..b8d222471c87e 100644 --- a/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/entity_analytics_management_page.cy.ts +++ b/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/entity_analytics_management_page.cy.ts @@ -15,6 +15,7 @@ import { LOCAL_QUERY_BAR_SELECTOR, RISK_SCORE_ERROR_PANEL, RISK_SCORE_STATUS, + LOCAL_QUERY_BAR_SEARCH_INPUT_SELECTOR, } from '../../screens/entity_analytics_management'; import { deleteRiskScore, installRiskScoreModule } from '../../tasks/api_calls/risk_scores'; @@ -31,7 +32,7 @@ import { interceptRiskInitError, } from '../../tasks/api_calls/risk_engine'; import { updateDateRangeInLocalDatePickers } from '../../tasks/date_picker'; -import { fillLocalSearchBar, submitLocalSearch } from '../../tasks/search_bar'; +import { submitLocalSearch } from '../../tasks/search_bar'; import { riskEngineStatusChange, upgradeRiskEngine, @@ -80,8 +81,7 @@ describe( it('risk scores reacts on change in search bar query', () => { cy.get(HOST_RISK_PREVIEW_TABLE_ROWS).should('have.length', 5); cy.get(USER_RISK_PREVIEW_TABLE_ROWS).should('have.length', 5); - - fillLocalSearchBar('host.name: "test-host1"'); + cy.get(LOCAL_QUERY_BAR_SEARCH_INPUT_SELECTOR).type('host.name: "test-host1"'); submitLocalSearch(LOCAL_QUERY_BAR_SELECTOR); cy.get(HOST_RISK_PREVIEW_TABLE_ROWS).should('have.length', 1); diff --git a/x-pack/test/security_solution_cypress/cypress/screens/entity_analytics_management.ts b/x-pack/test/security_solution_cypress/cypress/screens/entity_analytics_management.ts index 481c12fd9232e..e1d62ffb420c8 100644 --- a/x-pack/test/security_solution_cypress/cypress/screens/entity_analytics_management.ts +++ b/x-pack/test/security_solution_cypress/cypress/screens/entity_analytics_management.ts @@ -23,6 +23,9 @@ export const RISK_PREVIEW_ERROR_BUTTON = '[data-test-subj="risk-preview-error-bu export const LOCAL_QUERY_BAR_SELECTOR = getDataTestSubjectSelector('risk-score-preview-search-bar'); +export const LOCAL_QUERY_BAR_SEARCH_INPUT_SELECTOR = + '[data-test-subj="risk-score-preview-search-bar-input"]'; + export const RISK_SCORE_ERROR_PANEL = '[data-test-subj="risk-score-error-panel"]'; export const RISK_SCORE_UPDATE_CANCEL = '[data-test-subj="risk-score-update-cancel"]'; diff --git a/x-pack/test/security_solution_cypress/cypress/tasks/entity_analytics.ts b/x-pack/test/security_solution_cypress/cypress/tasks/entity_analytics.ts index bb02c196ac92e..5d84c28100fee 100644 --- a/x-pack/test/security_solution_cypress/cypress/tasks/entity_analytics.ts +++ b/x-pack/test/security_solution_cypress/cypress/tasks/entity_analytics.ts @@ -26,13 +26,13 @@ import { } from '../screens/entity_analytics_management'; import { visitWithTimeRange } from './navigation'; import { GET_DATE_PICKER_APPLY_BUTTON, GLOBAL_FILTERS_CONTAINER } from '../screens/date_picker'; -import { LOADING_SPINNER } from '../screens/loading'; +import { REFRESH_BUTTON } from '../screens/security_header'; export const updateDashboardTimeRange = () => { // eslint-disable-next-line cypress/no-force cy.get(GET_DATE_PICKER_APPLY_BUTTON(GLOBAL_FILTERS_CONTAINER)).click({ force: true }); // Force to fix global timerange flakiness - cy.get(LOADING_SPINNER).should('exist'); - cy.get(LOADING_SPINNER).should('not.exist'); + cy.get(REFRESH_BUTTON).click(); + cy.get(REFRESH_BUTTON).should('not.have.attr', 'aria-label', 'Needs updating'); }; export const waitForAnomaliesToBeLoaded = () => {