Skip to content

Commit 15eec5a

Browse files
authored
[SIEM] Fixes test flakiness (#65510)
* adds 'Configures a new connector' test * refactor code * updates configure_cases screen selectors * removes 'configure connector' test flakiness
1 parent 642b03b commit 15eec5a

File tree

7 files changed

+155
-4
lines changed

7 files changed

+155
-4
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
import { serviceNowConnector } from '../objects/case';
7+
8+
import { TOASTER } from '../screens/configure_cases';
9+
10+
import { goToEditExternalConnection } from '../tasks/all_cases';
11+
import {
12+
addServiceNowConnector,
13+
openAddNewConnectorOption,
14+
saveChanges,
15+
selectLastConnectorCreated,
16+
} from '../tasks/configure_cases';
17+
import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';
18+
19+
import { CASES } from '../urls/navigation';
20+
21+
describe('Cases connectors', () => {
22+
before(() => {
23+
cy.server();
24+
cy.route('POST', '**/api/action').as('createConnector');
25+
cy.route('POST', '**/api/cases/configure').as('saveConnector');
26+
});
27+
28+
it('Configures a new connector', () => {
29+
loginAndWaitForPageWithoutDateRange(CASES);
30+
goToEditExternalConnection();
31+
openAddNewConnectorOption();
32+
addServiceNowConnector(serviceNowConnector);
33+
34+
cy.wait('@createConnector')
35+
.its('status')
36+
.should('eql', 200);
37+
cy.get(TOASTER).should('have.text', "Created 'New connector'");
38+
39+
selectLastConnectorCreated();
40+
saveChanges();
41+
42+
cy.wait('@saveConnector', { timeout: 10000 })
43+
.its('status')
44+
.should('eql', 200);
45+
cy.get(TOASTER).should('have.text', 'Saved external connection settings');
46+
});
47+
});

x-pack/plugins/siem/cypress/objects/case.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ export interface TestCase {
1414
reporter: string;
1515
}
1616

17+
export interface Connector {
18+
connectorName: string;
19+
URL: string;
20+
username: string;
21+
password: string;
22+
}
23+
1724
const caseTimeline: Timeline = {
1825
title: 'SIEM test',
1926
description: 'description',
@@ -27,3 +34,10 @@ export const case1: TestCase = {
2734
timeline: caseTimeline,
2835
reporter: 'elastic',
2936
};
37+
38+
export const serviceNowConnector: Connector = {
39+
connectorName: 'New connector',
40+
URL: 'https://www.test.service-now.com',
41+
username: 'Username Name',
42+
password: 'password',
43+
};

x-pack/plugins/siem/cypress/screens/all_cases.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ export const ALL_CASES_TAGS = (index: number) => {
3939
};
4040

4141
export const ALL_CASES_TAGS_COUNT = '[data-test-subj="options-filter-popover-button-Tags"]';
42+
43+
export const EDIT_EXTERNAL_CONNECTION = '[data-test-subj="configure-case-button"]';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export const ADD_NEW_CONNECTOR_OPTION_LINK =
8+
'[data-test-subj="case-configure-add-connector-button"]';
9+
10+
export const CONNECTOR = (id: string) => {
11+
return `[data-test-subj='dropdown-connector-${id}']`;
12+
};
13+
14+
export const CONNECTOR_NAME = '[data-test-subj="nameInput"]';
15+
16+
export const CONNECTORS_DROPDOWN = '[data-test-subj="dropdown-connectors"]';
17+
18+
export const PASSWORD = '[data-test-subj="connector-servicenow-password-form-input"]';
19+
20+
export const SAVE_BTN = '[data-test-subj="saveNewActionButton"]';
21+
22+
export const SAVE_CHANGES_BTN = '[data-test-subj="case-configure-action-bottom-bar-save-button"]';
23+
24+
export const SERVICE_NOW_CONNECTOR_CARD = '[data-test-subj=".servicenow-card"]';
25+
26+
export const TOASTER = '[data-test-subj="euiToastHeader"]';
27+
28+
export const URL = '[data-test-subj="apiUrlFromInput"]';
29+
30+
export const USERNAME = '[data-test-subj="connector-servicenow-username-form-input"]';

x-pack/plugins/siem/cypress/tasks/all_cases.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { ALL_CASES_NAME, ALL_CASES_CREATE_NEW_CASE_BTN } from '../screens/all_cases';
7+
import {
8+
ALL_CASES_NAME,
9+
ALL_CASES_CREATE_NEW_CASE_BTN,
10+
EDIT_EXTERNAL_CONNECTION,
11+
} from '../screens/all_cases';
812

913
export const goToCreateNewCase = () => {
1014
cy.get(ALL_CASES_CREATE_NEW_CASE_BTN).click({ force: true });
@@ -13,3 +17,7 @@ export const goToCreateNewCase = () => {
1317
export const goToCaseDetails = () => {
1418
cy.get(ALL_CASES_NAME).click({ force: true });
1519
};
20+
21+
export const goToEditExternalConnection = () => {
22+
cy.get(EDIT_EXTERNAL_CONNECTION).click({ force: true });
23+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import {
8+
ADD_NEW_CONNECTOR_OPTION_LINK,
9+
CONNECTOR,
10+
CONNECTOR_NAME,
11+
CONNECTORS_DROPDOWN,
12+
PASSWORD,
13+
SAVE_BTN,
14+
SAVE_CHANGES_BTN,
15+
SERVICE_NOW_CONNECTOR_CARD,
16+
URL,
17+
USERNAME,
18+
} from '../screens/configure_cases';
19+
import { MAIN_PAGE } from '../screens/siem_main';
20+
21+
import { Connector } from '../objects/case';
22+
23+
export const addServiceNowConnector = (connector: Connector) => {
24+
cy.get(SERVICE_NOW_CONNECTOR_CARD).click();
25+
cy.get(CONNECTOR_NAME).type(connector.connectorName);
26+
cy.get(URL).type(connector.URL);
27+
cy.get(USERNAME).type(connector.username);
28+
cy.get(PASSWORD).type(connector.password);
29+
cy.get(SAVE_BTN).click({ force: true });
30+
};
31+
32+
export const openAddNewConnectorOption = () => {
33+
cy.get(MAIN_PAGE).then($page => {
34+
if ($page.find(SERVICE_NOW_CONNECTOR_CARD).length !== 1) {
35+
cy.wait(1000);
36+
cy.get(ADD_NEW_CONNECTOR_OPTION_LINK).click({ force: true });
37+
}
38+
});
39+
};
40+
41+
export const saveChanges = () => {
42+
cy.get(SAVE_CHANGES_BTN).click();
43+
};
44+
45+
export const selectLastConnectorCreated = () => {
46+
cy.get(CONNECTORS_DROPDOWN).click({ force: true });
47+
cy.get('@createConnector')
48+
.its('response')
49+
.then(response => {
50+
cy.get(CONNECTOR(response.body.id)).click();
51+
});
52+
};

x-pack/plugins/siem/public/pages/case/components/configure_cases/connectors_dropdown.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ const ConnectorsDropdownComponent: React.FC<Props> = ({
6565
/>
6666
</EuiFlexItem>
6767
<EuiFlexItem>
68-
<span data-test-subj={`dropdown-connector-${connector.id}`}>
69-
{connector.name}
70-
</span>
68+
<span>{connector.name}</span>
7169
</EuiFlexItem>
7270
</EuiFlexGroup>
7371
),

0 commit comments

Comments
 (0)