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

[SIEM] Fixes failing Cypress tests #57202

Merged
merged 4 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
} from '../../../screens/hosts/events';
import { DEFAULT_TIMEOUT } from '../../lib/util/helpers';

import { clearSearchBar } from '../../../tasks/header';

const defaultHeadersInDefaultEcsCategory = [
{ id: '@timestamp' },
{ id: 'message' },
Expand Down Expand Up @@ -133,11 +135,15 @@ describe('Events Viewer', () => {
before(() => {
loginAndWaitForPage(HOSTS_PAGE);
openEvents();
waitsForEventsToBeLoaded();
});

afterEach(() => {
clearSearchBar();
});

it('filters the events by applying filter criteria from the search bar at the top of the page', () => {
const filterInput = '4bf34c1c-eaa9-46de-8921-67a4ccc49829'; // this will never match real data
waitsForEventsToBeLoaded();
cy.get(HEADER_SUBTITLE)
.invoke('text')
.then(initialNumberOfEvents => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ describe('toggle column in timeline', () => {
'exist'
);

cy.get(
`[data-test-subj="timeline"] [data-test-subj="toggle-field-${timestampField}"]`
).uncheck({ force: true });
cy.get(`[data-test-subj="timeline"] [data-test-subj="toggle-field-${timestampField}"]`, {
timeout: DEFAULT_TIMEOUT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MadameSheema should we move DEFAULT_TIMEOUT into cypress.json, or is the intention to only use it for slow actions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rylnd timeouts are a little bit tricky in Cypress. These are the ones that we can set in the configuration (https://docs.cypress.io/guides/references/configuration.html#Timeouts). If we extract that time out to the json file, as defaultCommandTimeout that timeout is only for the element in the DOM but when we put the timeout like that, we are also setting that timeout to the next action in this case the uncheck so in this case is used with intention. Nevertheless as now are tests are faster I'll revisit all of them in the refactor I'm working on. But for now for having the tests working with the latest master changes I would say that is ok :)

}).uncheck({ force: true });

cy.get(`[data-test-subj="timeline"] [data-test-subj="header-text-${timestampField}"]`).should(
'not.exist'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,32 @@ describe('url state', () => {
.first()
.click({ force: true });

cy.get(DATE_PICKER_ABSOLUTE_INPUT, { timeout: DEFAULT_TIMEOUT }).type(
`{selectall}{backspace}${ABSOLUTE_DATE_RANGE.newStartTimeTyped}`
);
cy.get(DATE_PICKER_ABSOLUTE_INPUT, { timeout: DEFAULT_TIMEOUT })
.clear()
.type(`${ABSOLUTE_DATE_RANGE.newStartTimeTyped}`);

cy.get(DATE_PICKER_APPLY_BUTTON, { timeout: DEFAULT_TIMEOUT })
.click({ force: true })
.invoke('text')
.invoke('text', { timeout: DEFAULT_TIMEOUT })
.should('not.equal', 'Updating');

cy.get('[data-test-subj="table-topNFlowSource-loading-false"]', {
timeout: DEFAULT_TIMEOUT,
}).should('exist');

cy.get(DATE_PICKER_END_DATE_POPOVER_BUTTON).click({ force: true });

cy.get(DATE_PICKER_ABSOLUTE_TAB)
.first()
.click({ force: true });

cy.get(DATE_PICKER_ABSOLUTE_INPUT, { timeout: DEFAULT_TIMEOUT }).type(
`{selectall}{backspace}${ABSOLUTE_DATE_RANGE.newEndTimeTyped}`
);
cy.get(DATE_PICKER_ABSOLUTE_INPUT, { timeout: DEFAULT_TIMEOUT })
.clear()
.type(`${ABSOLUTE_DATE_RANGE.newEndTimeTyped}`);

cy.get(DATE_PICKER_APPLY_BUTTON, { timeout: DEFAULT_TIMEOUT })
.click({ force: true })
.invoke('text')
.invoke('text', { timeout: DEFAULT_TIMEOUT })
.should('not.equal', 'Updating');

cy.url().should(
Expand Down
9 changes: 9 additions & 0 deletions x-pack/legacy/plugins/siem/cypress/tasks/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { KQL_INPUT } from '../screens/header';
import { DEFAULT_TIMEOUT } from '../tasks/login';

export const navigateFromHeaderTo = (page: string) => {
cy.get(page).click({ force: true });
};

export const clearSearchBar = () => {
cy.get(KQL_INPUT, { timeout: DEFAULT_TIMEOUT })
.clear()
.type('{enter}');
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const clearFieldsBrowser = () => {
};

export const filterFieldsBrowser = (fieldName: string) => {
cy.get(FIELDS_BROWSER_FILTER_INPUT)
cy.get(FIELDS_BROWSER_FILTER_INPUT, { timeout: DEFAULT_TIMEOUT })
.type(fieldName)
.should('not.have.class', 'euiFieldSearch-isLoading');
};
Expand Down