Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] Reusing Cypress tests POC1 #162023

Closed
wants to merge 11 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export default defineCypressConfig({
e2e: {
baseUrl: 'http://localhost:5601',
experimentalMemoryManagement: true,
specPattern: './cypress/e2e/**/*.cy.ts',
specPattern: [
'./cypress/e2e/**/*.cy.ts',
'../../test/security_solution_cypress/e2e/**/*.cy.ts',
],
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ import { login, visitWithoutDateRange } from '../../tasks/login';
import { SECURITY_DETECTIONS_RULES_URL } from '../../urls/navigation';
import { createRule } from '../../tasks/api_calls/rules';
import { loadPrepackagedTimelineTemplates } from '../../tasks/api_calls/timelines';
import { cleanKibana, resetRulesTableState, deleteAlertsAndRules } from '../../tasks/common';
import {
cleanKibana,
resetRulesTableState,
deleteAlertsAndRules,
waitForPageToBeLoaded,
} from '../../tasks/common';

import {
getEqlRule,
Expand Down Expand Up @@ -136,7 +141,7 @@ describe('Detection rules, bulk edit', () => {
createRule(getNewTermsRule({ ...defaultRuleData, rule_id: '6' }));

visitWithoutDateRange(SECURITY_DETECTIONS_RULES_URL);

waitForPageToBeLoaded();
waitForRulesTableToBeLoaded();
});

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import {
import { getHostIpFilter } from '../../objects/filter';

import { HOSTS_URL } from '../../urls/navigation';
import { waitForPageToBeLoaded } from '../../tasks/common';
import { waitForAllHostsToBeLoaded } from '../../tasks/hosts/all_hosts';

describe('SearchBar', () => {
beforeEach(() => {
login();
visit(HOSTS_URL);
waitForPageToBeLoaded();
waitForAllHostsToBeLoaded();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import {
openTableInspectModal,
} from '../../tasks/inspect';
import { login, visit } from '../../tasks/login';
import {
postDataView,
waitForPageToBeLoaded,
waitForWelcomePanelToBeLoaded,
} from '../../tasks/common';
import { postDataView, waitForWelcomePanelToBeLoaded } from '../../tasks/common';
import { esArchiverLoad, esArchiverUnload } from '../../tasks/es_archiver';
import { selectDataView } from '../../tasks/sourcerer';

Expand Down Expand Up @@ -52,7 +48,6 @@ describe('Inspect Explore pages', () => {
visit(url, {
onLoad: () => {
waitForWelcomePanelToBeLoaded();
waitForPageToBeLoaded();
selectDataView(DATA_VIEW);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ import {
TIMELINE_ROW_RENDERERS_SURICATA_SIGNATURE_TOOLTIP,
TIMELINE_ROW_RENDERERS_SURICATA_LINK_TOOLTIP,
} from '../../../screens/timeline';
import {
cleanKibana,
deleteTimelines,
waitForPageToBeLoaded,
waitForWelcomePanelToBeLoaded,
} from '../../../tasks/common';
import { cleanKibana, deleteTimelines, waitForWelcomePanelToBeLoaded } from '../../../tasks/common';
import { waitForAllHostsToBeLoaded } from '../../../tasks/hosts/all_hosts';

import { login, visit } from '../../../tasks/login';
Expand All @@ -40,7 +35,6 @@ describe('Row renderers', () => {
visit(HOSTS_URL, {
onLoad: () => {
waitForWelcomePanelToBeLoaded();
waitForPageToBeLoaded();
waitForAllHostsToBeLoaded();
},
});
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/security_solution/cypress/tasks/all_cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ import {
ALL_CASES_CREATE_NEW_CASE_BTN,
EDIT_EXTERNAL_CONNECTION,
} from '../screens/all_cases';
import { waitForPageToBeLoaded } from './common';

export const goToCreateNewCase = () => {
cy.get(ALL_CASES_CREATE_NEW_CASE_BTN, { timeout: 60000 }).click({ force: true });
waitForPageToBeLoaded();
};

export const goToCaseDetails = () => {
waitForPageToBeLoaded();
cy.get(ALL_CASES_NAME).click({ force: true });
};

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/security_solution/cypress/tasks/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export const cleanKibana = () => {

export const deleteAlertsAndRules = () => {
cy.log('Delete all alerts and rules');
cy.log(Cypress.env('ELASTICSEARCH_URL'));
cy.log('GLOOOOOO');
const kibanaIndexUrl = `${Cypress.env('ELASTICSEARCH_URL')}/.kibana_\*`;

rootRequest({
Expand Down
13 changes: 0 additions & 13 deletions x-pack/plugins/security_solution/cypress/tasks/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Url from 'url';
import type { ROLES } from '../../common/test';
import { NEW_FEATURES_TOUR_STORAGE_KEYS } from '../../common/constants';
import { hostDetailsUrl, LOGOUT_URL, userDetailsUrl } from '../urls/navigation';
import { waitForPageToBeLoaded } from './common';

/**
* Credentials in the `kibana.dev.yml` config file will be used to authenticate
Expand Down Expand Up @@ -314,13 +313,6 @@ const disableNewFeaturesTours = (window: Window) => {
* Kibana global nav to be displayed before continuing
*/

export const waitForPage = (url: string) => {
cy.visit(
`${url}?timerange=(global:(linkTo:!(timeline),timerange:(from:1547914976217,fromStr:'2019-01-19T16:22:56.217Z',kind:relative,to:1579537385745,toStr:now)),timeline:(linkTo:!(global),timerange:(from:1547914976217,fromStr:'2019-01-19T16:22:56.217Z',kind:relative,to:1579537385745,toStr:now)))`
);
waitForPageToBeLoaded();
};

export const visit = (url: string, options: Partial<Cypress.VisitOptions> = {}, role?: ROLES) => {
const timerangeConfig = {
from: 1547914976217,
Expand Down Expand Up @@ -356,29 +348,25 @@ export const visit = (url: string, options: Partial<Cypress.VisitOptions> = {},
options.onLoad?.(win);
},
});
waitForPageToBeLoaded();
};

export const visitWithoutDateRange = (url: string, role?: ROLES) => {
cy.visit(role ? getUrlWithRoute(role, url) : url, {
onBeforeLoad: disableNewFeaturesTours,
});
waitForPageToBeLoaded();
};

export const visitWithUser = (url: string, user: User) => {
cy.visit(constructUrlWithUser(user, url), {
onBeforeLoad: disableNewFeaturesTours,
});
waitForPageToBeLoaded();
};

export const visitTimeline = (timelineId: string, role?: ROLES) => {
const route = `/app/security/timelines?timeline=(id:'${timelineId}',isOpen:!t)`;
cy.visit(role ? getUrlWithRoute(role, route) : route, {
onBeforeLoad: disableNewFeaturesTours,
});
waitForPageToBeLoaded();
};

export const visitHostDetailsPage = (hostName = 'suricata-iowa') => {
Expand All @@ -393,7 +381,6 @@ export const visitUserDetailsPage = (userName = 'test') => {

export const waitForPageWithoutDateRange = (url: string, role?: ROLES) => {
cy.visit(role ? getUrlWithRoute(role, url) : url);
waitForPageToBeLoaded();
};

export const logout = () => {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/security_solution/cypress/tasks/sourcerer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { HOSTS_STAT, SOURCERER } from '../screens/sourcerer';
import { HOSTS_URL } from '../urls/navigation';
import { visit, waitForPage } from './login';
import { visit } from './login';
import { openTimelineUsingToggle } from './security_main';
import { DEFAULT_ALERTS_INDEX } from '../../common/constants';
import { rootRequest } from './common';
Expand Down Expand Up @@ -110,7 +110,7 @@ export const addIndexToDefault = (index: string) => {

cy.get('button[data-test-subj="advancedSetting-saveButton"]').click();
cy.get('button[data-test-subj="windowReloadButton"]').click();
waitForPage(HOSTS_URL);
visit(HOSTS_URL);
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
} from '../../../screens/rule_details';

import { getDetails } from '../../../tasks/rule_details';
import { waitForPageToBeLoaded } from '../../../tasks/common';
import {
waitForRulesTableToBeLoaded,
goToTheRuleDetailsOf,
Expand Down Expand Up @@ -81,7 +80,6 @@ describe('After an upgrade, the custom query rule', () => {
visit(DETECTIONS_RULE_MANAGEMENT_URL);
waitForRulesTableToBeLoaded();
goToTheRuleDetailsOf(rule.name);
waitForPageToBeLoaded();
// Possible bug on first attempt sometimes redirects page back to alerts
// Going to retry the block once
cy.url().then((url) => {
Expand All @@ -92,7 +90,6 @@ describe('After an upgrade, the custom query rule', () => {
visit(DETECTIONS_RULE_MANAGEMENT_URL);
waitForRulesTableToBeLoaded();
goToTheRuleDetailsOf(rule.name);
waitForPageToBeLoaded();
}
});
cy.url().should('include', DETECTIONS_RULE_MANAGEMENT_URL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {

import { getDetails } from '../../../tasks/rule_details';
import { expandFirstAlert } from '../../../tasks/alerts';
import { waitForPageToBeLoaded } from '../../../tasks/common';
import {
goToTheRuleDetailsOf,
waitForRulesTableToBeLoaded,
Expand Down Expand Up @@ -76,7 +75,6 @@ describe('After an upgrade, the threshold rule', () => {
visit(DETECTIONS_RULE_MANAGEMENT_URL);
waitForRulesTableToBeLoaded();
goToTheRuleDetailsOf(rule.name);
waitForPageToBeLoaded();
});

it('Has the expected alerts number', () => {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/security_solution/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"extract-mitre-attacks": "node scripts/extract_tactics_techniques_mitre.js && node ../../../scripts/eslint ./public/detections/mitre/mitre_tactics_techniques.ts --fix",
"build-beat-doc": "node scripts/beat_docs/build.js && node ../../../scripts/eslint ../timelines/server/utils/beat_schema/fields.ts --fix",
"cypress": "../../../node_modules/.bin/cypress",
"cypress:open": "TZ=UTC node ./scripts/start_cypress_parallel open --spec './cypress/e2e/**/*.cy.ts' --config-file ./cypress/cypress.config.ts --ftr-config-file ../../../../../../x-pack/test/security_solution_cypress/cli_config",
"cypress:open": "TZ=UTC node ./scripts/start_cypress_parallel open --config-file ./cypress/cypress.config.ts --spec '../../{plugins/security_solution/cypress,test/security_solution_cypress}/e2e/**/*.cy.ts' --ftr-config-file ../../../../../../x-pack/test/security_solution_cypress/cli_config",
"cypress:open:ccs": "yarn cypress:open --config specPattern=./cypress/ccs_e2e/**/*.cy.ts",
"cypress:open:upgrade": "yarn cypress:open --config specPattern=./cypress/upgrade_e2e/**/*.cy.ts",
"cypress:run": "yarn cypress:run:reporter --browser chrome --spec './cypress/e2e/{,!(investigations,explore)/**/}*.cy.ts'; status=$?; yarn junit:merge && exit $status",
Expand All @@ -24,7 +24,7 @@
"cypress:dw:endpoint:run": "node ./scripts/start_cypress_parallel run --config-file ./public/management/cypress_endpoint.config.ts --ftr-config-file ../../../../../../x-pack/test/defend_workflows_cypress/endpoint_config --reporter ../../../node_modules/cypress-multi-reporters --reporter-options configFile=./cypress/reporter_config.json --concurrency 1; status=$?; yarn junit:merge && exit $status",
"cypress:dw:endpoint:open": "node ./scripts/start_cypress_parallel open --config-file ./public/management/cypress_endpoint.config.ts ts --ftr-config-file ../../../../../../x-pack/test/defend_workflows_cypress/endpoint_config",
"cypress:investigations:run": "yarn cypress:run:reporter --browser chrome --spec './cypress/e2e/investigations/**/*.cy.ts' --ftr-config-file ../../../../../../x-pack/test/security_solution_cypress/cli_config; status=$?; yarn junit:merge && exit $status",
"cypress:explore:run": "yarn cypress:run:reporter --browser chrome --spec './cypress/e2e/explore/**/*.cy.ts' --ftr-config-file ../../../../../../x-pack/test/security_solution_cypress/cli_config; status=$?; yarn junit:merge && exit $status",
"cypress:explore:run": "yarn cypress:run:reporter --browser chrome --spec '../../{plugins/security_solution/cypress,test/security_solution_cypress}/e2e/**/*.cy.ts' --ftr-config-file ../../../../../../x-pack/test/security_solution_cypress/cli_config; status=$?; yarn junit:merge && exit $status",
"junit:merge": "../../../node_modules/.bin/mochawesome-merge ../../../target/kibana-security-solution/cypress/results/mochawesome*.json > ../../../target/kibana-security-solution/cypress/results/output.json && ../../../node_modules/.bin/marge ../../../target/kibana-security-solution/cypress/results/output.json --reportDir ../../../target/kibana-security-solution/cypress/results && mkdir -p ../../../target/junit && cp ../../../target/kibana-security-solution/cypress/results/*.xml ../../../target/junit/",
"test:generate": "node scripts/endpoint/resolver_generator",
"mappings:generate": "node scripts/mappings/mappings_generator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ export const cli = () => {
config: {
e2e: {
baseUrl: `http://localhost:${kibanaPort}`,
specPattern: files,
},
env: customEnv,
},
Expand Down
41 changes: 41 additions & 0 deletions x-pack/test/security_solution_cypress/e2e/user_details.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { ALERT_FLYOUT } from '@kbn/security-solution-plugin/cypress/screens/alerts_details';
import { createRule } from '@kbn/security-solution-plugin/cypress/tasks/api_calls/rules';
import { cleanKibana } from '@kbn/security-solution-plugin/cypress/tasks/common';
import { waitForAlertsToPopulate } from '@kbn/security-solution-plugin/cypress/tasks/create_new_rule';
import { login, visitWithoutDateRange } from '@kbn/security-solution-plugin/cypress/tasks/login';
import { refreshPage } from '@kbn/security-solution-plugin/cypress/tasks/security_header';
import { getNewRule } from '@kbn/security-solution-plugin/cypress/objects/rule';
import { ALERTS_URL } from '@kbn/security-solution-plugin/cypress/urls/navigation';
import {
expandAlertTableCellValue,
openUserDetailsFlyout,
scrollAlertTableColumnIntoView,
} from '@kbn/security-solution-plugin/cypress/tasks/alerts';
import { USER_COLUMN } from '@kbn/security-solution-plugin/cypress/screens/alerts';

describe('user details flyout', () => {
beforeEach(() => {
cleanKibana();
login();
});

it('shows user detail flyout from alert table', () => {
visitWithoutDateRange(ALERTS_URL);
createRule(getNewRule({ query: 'user.name:*' }));
refreshPage();
waitForAlertsToPopulate();

scrollAlertTableColumnIntoView(USER_COLUMN);
expandAlertTableCellValue(USER_COLUMN);
openUserDetailsFlyout();

cy.get(ALERT_FLYOUT).should('be.visible');
});
});
3 changes: 2 additions & 1 deletion x-pack/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"@kbn/profiling-plugin",
"@kbn/observability-onboarding-plugin",
"@kbn/bfetch-plugin",
"@kbn/uptime-plugin"
"@kbn/uptime-plugin",
"@kbn/security-solution-plugin/cypress"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import { defineCypressConfig } from '@kbn/cypress-config';

export default defineCypressConfig({
defaultCommandTimeout: 60000,
execTimeout: 60000,
pageLoadTimeout: 60000,
defaultCommandTimeout: 150000,
execTimeout: 150000,
pageLoadTimeout: 150000,
responseTimeout: 60000,
screenshotsFolder: '../../../../../../target/kibana-security-solution/cypress/screenshots',
trashAssetsBeforeRuns: false,
Expand All @@ -23,6 +23,9 @@ export default defineCypressConfig({
experimentalRunAllSpecs: true,
experimentalMemoryManagement: true,
supportFile: './support/e2e.js',
specPattern: './e2e/**/*.cy.ts',
specPattern: [
'./e2e/**/*.cy.ts',
'../../../../../test/security_solution_cypress/e2e/**/*.cy.ts',
],
},
});
Loading