[8.14] [Entity Analytics] Flaky Cypress test fixes (#186081) (#187472)

# Backport
closes https://github.com/elastic/kibana/pull/187472

This will backport the following commits from `main` to `8.14`:
- [[Entity Analytics] Flaky Cypress test fixes
(#186081)](https://github.com/elastic/kibana/pull/186081)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Mark
Hopkin","email":"mark.hopkin@elastic.co"},"sourceCommit":{"committedDate":"2024-06-18T13:27:26Z","message":"[Entity
Analytics] Flaky Cypress test fixes (#186081)\n\n### Fix 1: Press
refresh button after using date picker on dashboard\r\n\r\nCloses
https://github.com/elastic/kibana/issues/183662\r\nCloses
https://github.com/elastic/kibana/issues/183635\r\nCloses
https://github.com/elastic/kibana/issues/183982\r\n\r\nWe shouldnt have
to do this, but there is some condition where clicking\r\napply gets the
UI in a stuck state and I cant figure it out.\r\n\r\n### Fix 2: Use more
specific selector for search bar on risk score\r\npreview
page\r\n\r\nCloses
https://github.com/elastic/kibana/issues/184133\r\n\r\nWe were using a
generic selector `[data-test-subj=\"unifiedQueryInput\"]\r\ntextarea`
which was bringing back two elements sometimes (no idea why),\r\nI have
given the box its own dedicated selector to hopefully prevent\r\nthis
from happening\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c34bb46c8aeb59dca0c92132dd34d2d9fca68728","branchLabelMapping":{"^v8.15.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:skip","Team:Entity
Analytics","v8.15.0"],"number":186081,"url":"https://github.com/elastic/kibana/pull/186081","mergeCommit":{"message":"[Entity
Analytics] Flaky Cypress test fixes (#186081)\n\n### Fix 1: Press
refresh button after using date picker on dashboard\r\n\r\nCloses
https://github.com/elastic/kibana/issues/183662\r\nCloses
https://github.com/elastic/kibana/issues/183635\r\nCloses
https://github.com/elastic/kibana/issues/183982\r\n\r\nWe shouldnt have
to do this, but there is some condition where clicking\r\napply gets the
UI in a stuck state and I cant figure it out.\r\n\r\n### Fix 2: Use more
specific selector for search bar on risk score\r\npreview
page\r\n\r\nCloses
https://github.com/elastic/kibana/issues/184133\r\n\r\nWe were using a
generic selector `[data-test-subj=\"unifiedQueryInput\"]\r\ntextarea`
which was bringing back two elements sometimes (no idea why),\r\nI have
given the box its own dedicated selector to hopefully prevent\r\nthis
from happening\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c34bb46c8aeb59dca0c92132dd34d2d9fca68728"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.15.0","labelRegex":"^v8.15.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/186081","number":186081,"mergeCommit":{"message":"[Entity
Analytics] Flaky Cypress test fixes (#186081)\n\n### Fix 1: Press
refresh button after using date picker on dashboard\r\n\r\nCloses
https://github.com/elastic/kibana/issues/183662\r\nCloses
https://github.com/elastic/kibana/issues/183635\r\nCloses
https://github.com/elastic/kibana/issues/183982\r\n\r\nWe shouldnt have
to do this, but there is some condition where clicking\r\napply gets the
UI in a stuck state and I cant figure it out.\r\n\r\n### Fix 2: Use more
specific selector for search bar on risk score\r\npreview
page\r\n\r\nCloses
https://github.com/elastic/kibana/issues/184133\r\n\r\nWe were using a
generic selector `[data-test-subj=\"unifiedQueryInput\"]\r\ntextarea`
which was bringing back two elements sometimes (no idea why),\r\nI have
given the box its own dedicated selector to hopefully prevent\r\nthis
from happening\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c34bb46c8aeb59dca0c92132dd34d2d9fca68728"}}]}]
BACKPORT-->

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Mark Hopkin 2024-07-04 10:10:01 +01:00 committed by GitHub
parent ded5277b26
commit cfd36e1877
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 12 additions and 6 deletions

View file

@ -227,6 +227,7 @@ const RiskEnginePreview = () => {
showDatePicker={true}
displayStyle={'inPage'}
submitButtonStyle={'iconOnly'}
dataTestSubj="risk-score-preview-search-bar-input"
/>
)}
</EuiFormRow>

View file

@ -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());
});

View file

@ -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);

View file

@ -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"]';

View file

@ -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 = () => {