Skip to content

Commit 8d9ac00

Browse files
[Security Solutions] Fixes Cypress tests for indicator match by making the selectors more specific (#91947)
## Summary Fixes the indicator match rules cypress e2e tests by making the selectors more specific. Previously other rules and forms code which live on the DOM beside the indicator match rules could interfere when moving around on the DOM. Now with more specific selectors this should be less likely to happen. If it does happen again I will make the selectors even more specific. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
1 parent a164411 commit 8d9ac00

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

x-pack/plugins/security_solution/cypress/integration/detection_rules/indicator_match_rule.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ import { loginAndWaitForPageWithoutDateRange } from '../../tasks/login';
9898

9999
import { DETECTIONS_URL, RULE_CREATION } from '../../urls/navigation';
100100

101-
// Skipped for 7.12 FF - flaky tests
102-
describe.skip('indicator match', () => {
101+
describe('indicator match', () => {
103102
describe('Detection rules, Indicator Match', () => {
104103
const expectedUrls = newThreatIndicatorRule.referenceUrls.join('');
105104
const expectedFalsePositives = newThreatIndicatorRule.falsePositivesExamples.join('');

x-pack/plugins/security_solution/cypress/screens/create_new_rule.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,24 @@ export const CREATE_AND_ACTIVATE_BTN = '[data-test-subj="create-activate"]';
3636

3737
export const CUSTOM_QUERY_INPUT = '[data-test-subj="queryInput"]';
3838

39+
export const THREAT_MAPPING_COMBO_BOX_INPUT =
40+
'[data-test-subj="threatMatchInput"] [data-test-subj="fieldAutocompleteComboBox"]';
41+
42+
export const THREAT_MATCH_CUSTOM_QUERY_INPUT =
43+
'[data-test-subj="detectionEngineStepDefineRuleQueryBar"] [data-test-subj="queryInput"]';
44+
45+
export const THREAT_MATCH_INDICATOR_QUERY_INPUT =
46+
'[data-test-subj="detectionEngineStepDefineRuleThreatMatchIndices"] [data-test-subj="queryInput"]';
47+
3948
export const THREAT_MATCH_QUERY_INPUT =
4049
'[data-test-subj="detectionEngineStepDefineThreatRuleQueryBar"] [data-test-subj="queryInput"]';
4150

51+
export const THREAT_MATCH_INDICATOR_INDEX =
52+
'[data-test-subj="detectionEngineStepDefineRuleIndices"] [data-test-subj="comboBoxInput"]';
53+
54+
export const THREAT_MATCH_INDICATOR_INDICATOR_INDEX =
55+
'[data-test-subj="detectionEngineStepDefineRuleThreatMatchIndices"] [data-test-subj="comboBoxInput"]';
56+
4257
export const THREAT_MATCH_AND_BUTTON = '[data-test-subj="andButton"]';
4358

4459
export const THREAT_ITEM_ENTRY_DELETE_BUTTON = '[data-test-subj="itemEntryDeleteButton"]';

x-pack/plugins/security_solution/cypress/tasks/create_new_rule.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ import {
8080
CUSTOM_QUERY_REQUIRED,
8181
RULES_CREATION_FORM,
8282
RULES_CREATION_PREVIEW,
83+
THREAT_MATCH_INDICATOR_INDEX,
84+
THREAT_MATCH_INDICATOR_INDICATOR_INDEX,
85+
THREAT_MATCH_CUSTOM_QUERY_INPUT,
86+
THREAT_MATCH_QUERY_INPUT,
87+
THREAT_MAPPING_COMBO_BOX_INPUT,
8388
} from '../screens/create_new_rule';
8489
import { TOAST_ERROR } from '../screens/shared';
8590
import { SERVER_SIDE_EVENT_COUNT } from '../screens/timeline';
@@ -325,17 +330,17 @@ export const fillIndicatorMatchRow = ({
325330
}) => {
326331
const computedRowNumber = rowNumber == null ? 1 : rowNumber;
327332
const computedValueRows = validColumns == null ? 'both' : validColumns;
328-
const OFFSET = 2;
329-
cy.get(COMBO_BOX_INPUT)
330-
.eq(computedRowNumber * OFFSET + 1)
333+
cy.get(THREAT_MAPPING_COMBO_BOX_INPUT)
334+
.eq(computedRowNumber * 2 - 2)
335+
.eq(0)
331336
.type(indexField);
332337
if (computedValueRows === 'indexField' || computedValueRows === 'both') {
333338
cy.get(`button[title="${indexField}"]`)
334339
.should('be.visible')
335340
.then(([e]) => e.click());
336341
}
337-
cy.get(COMBO_BOX_INPUT)
338-
.eq(computedRowNumber * OFFSET + 2)
342+
cy.get(THREAT_MAPPING_COMBO_BOX_INPUT)
343+
.eq(computedRowNumber * 2 - 1)
339344
.type(indicatorIndexField);
340345

341346
if (computedValueRows === 'indicatorField' || computedValueRows === 'both') {
@@ -393,19 +398,20 @@ export const getAboutContinueButton = () => cy.get(ABOUT_CONTINUE_BTN);
393398
export const getDefineContinueButton = () => cy.get(DEFINE_CONTINUE_BUTTON);
394399

395400
/** Returns the indicator index pattern */
396-
export const getIndicatorIndex = () => cy.get(COMBO_BOX_INPUT).eq(0);
401+
export const getIndicatorIndex = () => cy.get(THREAT_MATCH_INDICATOR_INDEX).eq(0);
397402

398403
/** Returns the indicator's indicator index */
399-
export const getIndicatorIndicatorIndex = () => cy.get(COMBO_BOX_INPUT).eq(2);
404+
export const getIndicatorIndicatorIndex = () =>
405+
cy.get(THREAT_MATCH_INDICATOR_INDICATOR_INDEX).eq(0);
400406

401407
/** Returns the index pattern's clear button */
402408
export const getIndexPatternClearButton = () => cy.get(COMBO_BOX_CLEAR_BTN);
403409

404410
/** Returns the custom query input */
405-
export const getCustomQueryInput = () => cy.get(CUSTOM_QUERY_INPUT).eq(0);
411+
export const getCustomQueryInput = () => cy.get(THREAT_MATCH_CUSTOM_QUERY_INPUT).eq(0);
406412

407413
/** Returns the custom query input */
408-
export const getCustomIndicatorQueryInput = () => cy.get(CUSTOM_QUERY_INPUT).eq(1);
414+
export const getCustomIndicatorQueryInput = () => cy.get(THREAT_MATCH_QUERY_INPUT).eq(0);
409415

410416
/** Returns custom query required content */
411417
export const getCustomQueryInvalidationText = () => cy.contains(CUSTOM_QUERY_REQUIRED);

0 commit comments

Comments
 (0)