Skip to content

Commit

Permalink
[SecuritySolution] Fix flaky cypress timeline templates test (#155513)
Browse files Browse the repository at this point in the history
## Summary

The test was guessing the created template was on page `2` but,
depending on the template data inserted, sometimes it is found on page
`3`.
This PR changes the test approach to search for the template name, so we
don't rely on guessing the page.
  • Loading branch information
semd authored Apr 21, 2023
1 parent a0aae1a commit 3e81f8f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { TIMELINE_TEMPLATES_URL } from '../../urls/navigation';
import { createTimelineTemplate } from '../../tasks/api_calls/timelines';
import { cleanKibana } from '../../tasks/common';
import { setRowsPerPageTo } from '../../tasks/table_pagination';
import { searchByTitle } from '../../tasks/table_pagination';

describe('Export timelines', () => {
before(() => {
Expand All @@ -27,13 +27,14 @@ describe('Export timelines', () => {
createTimelineTemplate(getTimelineTemplate()).then((response) => {
cy.wrap(response).as('templateResponse');
cy.wrap(response.body.data.persistTimeline.timeline.savedObjectId).as('templateId');
cy.wrap(response.body.data.persistTimeline.timeline.title).as('templateTitle');
});
login();
});

it('Exports a custom timeline template', function () {
visitWithoutDateRange(TIMELINE_TEMPLATES_URL);
setRowsPerPageTo(20);
searchByTitle(this.templateTitle);
exportTimeline(this.templateId);

cy.wait('@export').then(({ response }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ export const TABLE_FIRST_PAGE = tablePageSelector(1);
export const TABLE_SECOND_PAGE = tablePageSelector(2);

export const TABLE_SORT_COLUMN_BTN = '[data-test-subj="tableHeaderSortButton"]';

export const TABLE_SEARCH_BAR = '[data-test-subj="search-bar"]';
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
rowsPerPageSelector,
tablePageSelector,
TABLE_PER_PAGE_POPOVER_BTN,
TABLE_SEARCH_BAR,
TABLE_SORT_COLUMN_BTN,
} from '../screens/table_pagination';

Expand All @@ -33,6 +34,14 @@ export const setRowsPerPageTo = (rowsCount: number) => {
.should('not.exist');
};

export const searchByTitle = (title: string) => {
cy.get(LOADING_SPINNER).should('not.exist');
cy.get(TABLE_PER_PAGE_POPOVER_BTN).should('exist');
cy.get(TABLE_SEARCH_BAR).click({ force: true });
// EuiSearchBox needs the "search" event to be triggered, {enter} doesn't work
cy.get(TABLE_SEARCH_BAR).type(`"${title}"`).trigger('search');
};

export const expectRowsPerPage = (rowsCount: number) => {
cy.get(TABLE_PER_PAGE_POPOVER_BTN).contains(`Rows per page: ${rowsCount}`);
};
Expand Down

0 comments on commit 3e81f8f

Please sign in to comment.