From 0f2b1c0973e74278730d8c5b78b587cba1c61edf Mon Sep 17 00:00:00 2001 From: MadameSheema Date: Wed, 21 Oct 2020 12:30:04 +0200 Subject: [PATCH] [Security Solution] Fixes flaky test rules (#81040) * deletes the created rule in the after hook * fixes failing test * changes rule deletion order Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../integration/alerts_detection_rules_custom.spec.ts | 2 ++ .../cypress/integration/alerts_detection_rules_eql.spec.ts | 2 ++ .../cypress/integration/alerts_detection_rules_ml.spec.ts | 2 ++ .../integration/alerts_detection_rules_threshold.spec.ts | 2 ++ .../security_solution/cypress/screens/rule_details.ts | 4 ++++ .../cypress/tasks/alerts_detection_rules.ts | 6 ++++++ 6 files changed, 18 insertions(+) diff --git a/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_custom.spec.ts b/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_custom.spec.ts index d7a963ba4efa7..491f4f8952fd9 100644 --- a/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_custom.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_custom.spec.ts @@ -73,6 +73,7 @@ import { import { changeToThreeHundredRowsPerPage, deleteFirstRule, + deleteRule, deleteSelectedRules, editFirstRule, filterByCustomRules, @@ -119,6 +120,7 @@ describe('Custom detection rules creation', () => { }); after(() => { + deleteRule(); esArchiverUnload('timeline'); }); diff --git a/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_eql.spec.ts b/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_eql.spec.ts index 1b76e74d47bb1..bee4713ca7cda 100644 --- a/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_eql.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_eql.spec.ts @@ -55,6 +55,7 @@ import { } from '../tasks/alerts'; import { changeToThreeHundredRowsPerPage, + deleteRule, filterByCustomRules, goToCreateNewRule, goToRuleDetails, @@ -93,6 +94,7 @@ describe('Detection rules, EQL', () => { }); afterEach(() => { + deleteRule(); esArchiverUnload('timeline'); }); diff --git a/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_ml.spec.ts b/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_ml.spec.ts index 0f34e7d71e5fa..153c55fae59fe 100644 --- a/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_ml.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_ml.spec.ts @@ -44,6 +44,7 @@ import { } from '../tasks/alerts'; import { changeToThreeHundredRowsPerPage, + deleteRule, filterByCustomRules, goToCreateNewRule, goToRuleDetails, @@ -78,6 +79,7 @@ describe('Detection rules, machine learning', () => { }); after(() => { + deleteRule(); esArchiverUnload('prebuilt_rules_loaded'); }); diff --git a/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_threshold.spec.ts b/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_threshold.spec.ts index f997b9eb3bc51..a6f974256f3e4 100644 --- a/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_threshold.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_threshold.spec.ts @@ -56,6 +56,7 @@ import { } from '../tasks/alerts'; import { changeToThreeHundredRowsPerPage, + deleteRule, filterByCustomRules, goToCreateNewRule, goToRuleDetails, @@ -91,6 +92,7 @@ describe('Detection rules, threshold', () => { }); after(() => { + deleteRule(); esArchiverUnload('timeline'); }); diff --git a/x-pack/plugins/security_solution/cypress/screens/rule_details.ts b/x-pack/plugins/security_solution/cypress/screens/rule_details.ts index 5a376e95e38dd..e40b81ed0e856 100644 --- a/x-pack/plugins/security_solution/cypress/screens/rule_details.ts +++ b/x-pack/plugins/security_solution/cypress/screens/rule_details.ts @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +export const ALL_ACTIONS = '[data-test-subj="rules-details-popover-button-icon"]'; + export const ABOUT_INVESTIGATION_NOTES = '[data-test-subj="stepAboutDetailsNoteContent"]'; export const ABOUT_RULE_DESCRIPTION = '[data-test-subj=stepAboutRuleDetailsToggleDescriptionText]'; @@ -24,6 +26,8 @@ export const DETAILS_DESCRIPTION = '.euiDescriptionList__description'; export const DETAILS_TITLE = '.euiDescriptionList__title'; +export const DELETE_RULE = '[data-test-subj=rules-details-delete-rule]'; + export const FALSE_POSITIVES_DETAILS = 'False positive examples'; export const INDEX_PATTERNS_DETAILS = 'Index patterns'; diff --git a/x-pack/plugins/security_solution/cypress/tasks/alerts_detection_rules.ts b/x-pack/plugins/security_solution/cypress/tasks/alerts_detection_rules.ts index 8b494edaade3a..1c430e12b6b73 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/alerts_detection_rules.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/alerts_detection_rules.ts @@ -27,6 +27,7 @@ import { EDIT_RULE_ACTION_BTN, NEXT_BTN, } from '../screens/alerts_detection_rules'; +import { ALL_ACTIONS, DELETE_RULE } from '../screens/rule_details'; export const activateRule = (rulePosition: number) => { cy.get(RULE_SWITCH).eq(rulePosition).click({ force: true }); @@ -47,6 +48,11 @@ export const deleteFirstRule = () => { cy.get(DELETE_RULE_ACTION_BTN).click(); }; +export const deleteRule = () => { + cy.get(ALL_ACTIONS).click(); + cy.get(DELETE_RULE).click(); +}; + export const deleteSelectedRules = () => { cy.get(BULK_ACTIONS_BTN).click({ force: true }); cy.get(DELETE_RULE_BULK_BTN).click();