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] Fix flaky hover actions test #166492

Closed
wants to merge 3 commits into from
Closed
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 @@ -18,15 +18,14 @@ import {
clickOnFilterIn,
clickOnFilterOut,
clickOnShowTopN,
mouseoverOnToOverflowItem,
openHoverActions,
withHoverActionsReady,
} from '../../../tasks/network/flows';
import { openTimelineUsingToggle } from '../../../tasks/security_main';

const testDomain = 'myTest';

// tracked by https://github.com/elastic/kibana/issues/161874
describe.skip('Hover actions', { tags: ['@ess', '@serverless'] }, () => {
describe('Hover actions', { tags: ['@ess', '@serverless'] }, () => {
const onBeforeLoadCallback = (win: Cypress.AUTWindow) => {
// avoid cypress being held by windows prompt and timeout
cy.stub(win, 'prompt').returns(true);
Expand All @@ -43,18 +42,16 @@ describe.skip('Hover actions', { tags: ['@ess', '@serverless'] }, () => {
beforeEach(() => {
login();
visit(NETWORK_URL, { visitOptions: { onBeforeLoad: onBeforeLoadCallback } });
openHoverActions();
mouseoverOnToOverflowItem();
});

it('Adds global filter - filter in', () => {
clickOnFilterIn();
withHoverActionsReady(clickOnFilterIn);

cy.get(GLOBAL_SEARCH_BAR_FILTER_ITEM).should('have.text', `destination.domain: ${testDomain}`);
});

it('Adds global filter - filter out', () => {
clickOnFilterOut();
withHoverActionsReady(clickOnFilterOut);
cy.get(GLOBAL_SEARCH_BAR_FILTER_ITEM).should(
'contains.text',
`NOT destination.domain: ${testDomain}`
Expand All @@ -63,22 +60,22 @@ describe.skip('Hover actions', { tags: ['@ess', '@serverless'] }, () => {

it('Adds to timeline', () => {
const DATA_PROVIDER_ITEM_NUMBER = 1;
clickOnAddToTimeline();
withHoverActionsReady(clickOnAddToTimeline);
openTimelineUsingToggle();

cy.get(DATA_PROVIDERS).should('have.length', DATA_PROVIDER_ITEM_NUMBER);
cy.get(DATA_PROVIDERS).should('have.text', `destination.domain: "${testDomain}"`);
});

it('Show topN', () => {
clickOnShowTopN();
withHoverActionsReady(clickOnShowTopN);
cy.get(TOP_N_CONTAINER).should('exist').should('contain.text', 'Top destination.domain');
});

it('Copy value', () => {
cy.document().then((doc) => cy.spy(doc, 'execCommand').as('execCommand'));

clickOnCopyValue();
withHoverActionsReady(clickOnCopyValue);

cy.get('@execCommand').should('have.been.calledOnceWith', 'copy');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ export const mouseoverOnToOverflowItem = () => {
cy.get(OVERFLOW_ITEM).first().realHover();
};

/**
* What is crucial here is that we need to verify whether or not the actions portal element is visible,
* and only then we can perform the action. This is done immediately before any action is performed on the actions button itself,
* and if for some reason the actions portal element is not visible, we will try to hover over the actions activator element again.
* @param action
* @param maxTries
*/
export function withHoverActionsReady(action: () => void, maxTries = 10) {
// NOTE: not sure if this is precise enough, but it seems to work
const actionsButtonInPortal = '[data-euiportal="true"] button[data-test-subj*="cellActions"]';

// Check if actions portal element is visible
cy.get('body').then(($body) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if ($body.find(actionsButtonInPortal).length > 0) {
cy.get(actionsButtonInPortal).should('be.visible');
action();
} else if (maxTries <= 0) {
throw new Error(`Max tries reached. The element ${actionsButtonInPortal} is not visible.`);
} else {
openHoverActions();
mouseoverOnToOverflowItem();
withHoverActionsReady(action, maxTries - 1);
}
});
}

export const clickOnFilterIn = () => {
cy.get(FILTER_IN).first().click();
};
Expand Down