From a522145e6a5b09b924e26497b29422de9ade96aa Mon Sep 17 00:00:00 2001 From: mauceballos Date: Wed, 19 Oct 2022 17:01:05 -0300 Subject: [PATCH] feature search by parameters And , Or --- .../filters/Search-by-parameters.feature | 32 +++++++++++++++++++ ...in-filter-from-dashboard-to-events.feature | 3 +- .../pageobjects/wzd/filters/filters.page.js | 4 ++- .../The-user-types-particular-search.when.js | 10 ++++++ .../filters/the-query-is-accepted.then.js | 8 +++++ .../The-wazuh-admin-user-is-logged.given.js | 21 +++++++++++- .../cypress/integration/utils/driver.js | 17 ++++++++++ 7 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 test/cypress/cypress/integration/features/filters/Search-by-parameters.feature create mode 100644 test/cypress/cypress/integration/step-definitions/filters/The-user-types-particular-search.when.js create mode 100644 test/cypress/cypress/integration/step-definitions/filters/the-query-is-accepted.then.js diff --git a/test/cypress/cypress/integration/features/filters/Search-by-parameters.feature b/test/cypress/cypress/integration/features/filters/Search-by-parameters.feature new file mode 100644 index 0000000000..1e7aaa3d7f --- /dev/null +++ b/test/cypress/cypress/integration/features/filters/Search-by-parameters.feature @@ -0,0 +1,32 @@ +Feature: Search by parameters + + As a Wazuh user + I want to pin a filter + in order to aplly it across the modules + Background: + Given The wazuh admin user is logged + And The sample data is loaded + + Scenario Outline: Search by parameters with AND + When The user goes to + And The user types a particular search on the search bar + Then The query is accepted and the results should be displayed + Examples: + | Module Name | key | + | Security Events | cluster.name : "wazuh" and rule.level : "3" | + | Integrity Monitoring | cluster.name : "wazuh" and agent.id : "001" | + | NIST | cluster.name : "wazuh" and agent.name : "Ubuntu" | + | TSC | cluster.name : "wazuh" and agent.name : "Ubuntu" | + | PCIDSS | cluster.name : "wazuh" and agent.name : "Ubuntu" | + + Scenario Outline: Search by parameters with OR + When The user goes to + And The user types a particular search on the search bar + Then The query is accepted and the results should be displayed + Examples: + | Module Name | key | + | Security Events | cluster.name : "wazuh" or rule.level : "3" | + | Integrity Monitoring | cluster.name : "wazuh" or agent.id : "001" | + | NIST | cluster.name : "wazuh" or agent.name : "Ubuntu" | + | TSC | cluster.name : "wazuh" or agent.name : "Ubuntu" | + | PCIDSS | cluster.name : "wazuh" or agent.name : "Ubuntu" | \ No newline at end of file diff --git a/test/cypress/cypress/integration/features/filters/pin-filter-from-dashboard-to-events.feature b/test/cypress/cypress/integration/features/filters/pin-filter-from-dashboard-to-events.feature index 33cedffc3d..dc0f0cbcbc 100644 --- a/test/cypress/cypress/integration/features/filters/pin-filter-from-dashboard-to-events.feature +++ b/test/cypress/cypress/integration/features/filters/pin-filter-from-dashboard-to-events.feature @@ -26,5 +26,4 @@ Feature: Pin filter - from dashboard to event page | NIST | | TSC | | Policy Monitoring | - | PCIDSS | - + | PCIDSS | \ No newline at end of file diff --git a/test/cypress/cypress/integration/pageobjects/wzd/filters/filters.page.js b/test/cypress/cypress/integration/pageobjects/wzd/filters/filters.page.js index 8cab080bb5..bfad0d8e19 100644 --- a/test/cypress/cypress/integration/pageobjects/wzd/filters/filters.page.js +++ b/test/cypress/cypress/integration/pageobjects/wzd/filters/filters.page.js @@ -13,5 +13,7 @@ export const FILTERS_PAGE = { pinnedFilter: '[data-test-subj="filter filter-enabled filter-key-rule.level filter-value-7 filter-pinned "]', eventsButton: '//*[contains(@class,"euiTabs")]//*[contains(text(),"Events")]', removeFilterButton: '//*[contains(@class,"euiContextMenuPanel")]//*[contains(text(),"Delete")]', - operatorList: '.euiPanel[data-test-subj="comboBoxOptionsList filterOperatorList-optionsList"] .euiComboBoxOptionsList__rowWrap' + operatorList: '.euiPanel[data-test-subj="comboBoxOptionsList filterOperatorList-optionsList"] .euiComboBoxOptionsList__rowWrap', + searchInputSelector: '[role="combobox"] [data-test-subj="queryInput"]', + noResultMessage: '#moduleDashboard .euiCallOut--warning span' }; diff --git a/test/cypress/cypress/integration/step-definitions/filters/The-user-types-particular-search.when.js b/test/cypress/cypress/integration/step-definitions/filters/The-user-types-particular-search.when.js new file mode 100644 index 0000000000..d8f8e3c0fd --- /dev/null +++ b/test/cypress/cypress/integration/step-definitions/filters/The-user-types-particular-search.when.js @@ -0,0 +1,10 @@ +import { When } from 'cypress-cucumber-preprocessor/steps'; +import { fillField, elementIsVisible, getSelector, forceEnter} from '../../utils/driver'; +import { FILTERS_PAGE as pageName} from '../../utils/pages-constants'; +const searchInputSelector = getSelector('searchInputSelector', pageName); + +When('The user types a particular search {} on the search bar', (key) => { + elementIsVisible(searchInputSelector); + fillField(searchInputSelector, key); + forceEnter(searchInputSelector); +}); diff --git a/test/cypress/cypress/integration/step-definitions/filters/the-query-is-accepted.then.js b/test/cypress/cypress/integration/step-definitions/filters/the-query-is-accepted.then.js new file mode 100644 index 0000000000..50c71bde7d --- /dev/null +++ b/test/cypress/cypress/integration/step-definitions/filters/the-query-is-accepted.then.js @@ -0,0 +1,8 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; +import { elementIsNotVisible, getSelector } from '../../utils/driver'; +import { FILTERS_PAGE as pageName} from '../../utils/pages-constants'; +const noResultMessage = getSelector('noResultMessage', pageName); + +Then('The query is accepted and the results should be displayed', () => { + elementIsNotVisible(noResultMessage) +}) \ No newline at end of file diff --git a/test/cypress/cypress/integration/step-definitions/settings/The-wazuh-admin-user-is-logged.given.js b/test/cypress/cypress/integration/step-definitions/settings/The-wazuh-admin-user-is-logged.given.js index e21623fec3..0341d86291 100644 --- a/test/cypress/cypress/integration/step-definitions/settings/The-wazuh-admin-user-is-logged.given.js +++ b/test/cypress/cypress/integration/step-definitions/settings/The-wazuh-admin-user-is-logged.given.js @@ -1,10 +1,29 @@ import { Given } from 'cypress-cucumber-preprocessor/steps'; -import { navigate, elementIsVisible, getSelector } from '../../utils/driver'; +import { navigate, elementIsVisible, getSelector, getCookiesFromBrowser } from '../../utils/driver'; import { WAZUH_MENU_PAGE as pageName} from '../../utils/pages-constants'; const wazuhMenuButton = getSelector('wazuhMenuButton', pageName); +let urlsList = ['https://localhost:5601/elastic/samplealerts/security','https://localhost:5601/elastic/samplealerts/auditing-policy-monitoring','https://localhost:5601/elastic/samplealerts/threat-detection']; +let urlBodys = [{"alertCount": 27000,"index": "wazuh-alerts-4.x-sample-security"},{"alertCount": 12000,"index": "wazuh-alerts-4.x-sample-auditing-policy-monitoring"},{"alertCount": 15000,"index": "wazuh-alerts-4.x-sample-threat-detection"}] Given('The wazuh admin user is logged', () => { if (Cypress.env('type') != 'wzd') { navigate("app/wazuh");}else{navigate("/")} elementIsVisible(wazuhMenuButton); }) + +Given('The sample data is loaded', () => { + cy.readFile('cookies.json').then((cookies) => { + let headersFormat = {"content-type":"application/json; charset=utf-8","Cookie": getCookiesFromBrowser(cookies),"Accept":"application/json, text/plain, */*","Accept-Encoding":"gzip, deflate, br","osd-xsrf":"kibana"}; + for(let i = 0; i < urlsList.length; i++){ + cy.request({ + method: 'POST', + url: urlsList[i], + headers: headersFormat, + body: urlBodys[i] + }).should((response) => { + expect(response.status).to.eq(200) + }) + } + + }) +}) \ No newline at end of file diff --git a/test/cypress/cypress/integration/utils/driver.js b/test/cypress/cypress/integration/utils/driver.js index 2be70eebe3..1e1743856e 100644 --- a/test/cypress/cypress/integration/utils/driver.js +++ b/test/cypress/cypress/integration/utils/driver.js @@ -149,3 +149,20 @@ export const xpathCheckInformationElement= (webLocator, optionsNames, optionLen expect(optionsNames, 'has expected [' + optionsNames + '] text in each paragraph [' + paragraphs + ']').to.contains(paragraphs) }) } + + +export const getCookiesFromBrowser = (values) => { + return values.filter(item=>['wz-token', 'wz-user', 'wz-api', 'security_authentication'].includes(item.name)) + .map(item=>{ + return `${item.name}:${item.value}` + }).join(';'); +} + +export const retrieveInformation = (url,method,headers,bodyPost) => { + return cy.request({ + method: method, + url: url, + headers: headers, + body: bodyPost + }).as('response'); +} \ No newline at end of file