Skip to content

Commit

Permalink
[APM] Fix Deep Links Cypress Flaky Test (elastic#206000)
Browse files Browse the repository at this point in the history
## Summary

Closes elastic#205936

This PR aims to solve the flakiness of deep_links.cy test.

- Instead of doing everything under 2 tests, we run a test for each
assertion and clean everything up.
- Ensures scroll div has content to be able to scroll
- scrolls to center or bottom depending on the position
  • Loading branch information
rmyz authored Jan 9, 2025
1 parent 49690d7 commit 45f3241
Showing 1 changed file with 82 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,83 +10,97 @@ describe('Applications deep links', () => {
cy.loginAsViewerUser();
});

it('navigates to Application links on "application" search', () => {
cy.visitKibana('/');
navigatesToApmLinks('applications');
});
['apm', 'applications'].forEach((keyword) => {
describe(`Deep links for ${keyword} keyword`, () => {
it('contains all the expected deep links', () => {
// navigates to home page
cy.visitKibana('/');
// Wait until the page content is fully loaded
// otherwise, the search results may disappear before all checks are completed, making this test flaky
cy.waitUntilPageContentIsLoaded();
cy.getByTestSubj('nav-search-input').should('be.visible').type(keyword, { force: true });

it('navigates to Application links on "apm" search', () => {
cy.visitKibana('/');
navigatesToApmLinks('apm');
});
cy.contains('Applications');
cy.contains('Applications / Service Inventory');
cy.contains('Applications / Service groups');
// scroll to the center & bottom because results are not rendering otherwise
scrollToPositionResults('center');
cy.contains('Applications / Traces');
cy.contains('Applications / Service Map');
scrollToPositionResults('bottom');
cy.contains('Applications / Dependencies');
cy.contains('Applications / Settings');
});

function navigatesToApmLinks(keyword: string) {
// Wait until the page content is fully loaded
// otherwise, the search results may disappear before all checks are completed, making this test flaky
cy.waitUntilPageContentIsLoaded();
cy.getByTestSubj('nav-search-input')
.should('be.visible')
.type(keyword, { force: true })
.focus();
cy.contains('Applications');
cy.contains('Applications / Service Inventory');
cy.contains('Applications / Service groups');
cy.contains('Applications / Traces');
cy.contains('Applications / Service Map');
// scroll to the bottom because results are not rendering otherwise
scrollToBottomResults();
cy.contains('Applications / Dependencies');
cy.contains('Applications / Settings');
it('navigates to Service Inventory page', () => {
cy.visitKibana('/');
assertDeepLink(keyword, 'Applications / Service Inventory', '/apm/services');
});

// navigates to home page
// Force click because welcome screen changes
// https://github.com/elastic/kibana/pull/108193
cy.contains('Applications').click({ force: true });
cy.url().should('include', '/apm/services');
it('navigates to Service groups page', () => {
cy.visitKibana('/');
assertDeepLink(keyword, 'Applications / Service groups', '/apm/service-groups');
});

cy.waitUntilPageContentIsLoaded();
cy.getByTestSubj('nav-search-input').should('be.visible').type(keyword, { force: true });
// navigates to services page
cy.contains('Applications / Service Inventory').click({ force: true });
cy.url().should('include', '/apm/services');
it('navigates to Traces page', () => {
cy.visitKibana('/');
assertDeepLink(keyword, 'Applications / Traces', '/apm/traces', 'center');
});

cy.waitUntilPageContentIsLoaded();
cy.getByTestSubj('nav-search-input').should('be.visible').type(keyword, { force: true });
// navigates to service groups page
cy.contains('Applications / Service groups').click({ force: true });
cy.url().should('include', '/apm/service-groups');
it('navigates to Service Map page', () => {
cy.visitKibana('/');
assertDeepLink(keyword, 'Applications / Service Map', '/apm/service-map', 'center');
});

cy.waitUntilPageContentIsLoaded();
cy.getByTestSubj('nav-search-input').should('be.visible').type(keyword, { force: true });
// navigates to traces page
cy.contains('Applications / Traces').click({ force: true });
cy.url().should('include', '/apm/traces');
it('navigates to Dependencies page', () => {
cy.visitKibana('/');
assertDeepLink(
keyword,
'Applications / Dependencies',
'/apm/dependencies/inventory',
'bottom'
);
});

cy.waitUntilPageContentIsLoaded();
cy.getByTestSubj('nav-search-input').should('be.visible').type(keyword, { force: true });
scrollToBottomResults();
// navigates to service maps
cy.contains('Applications / Service Map').click({ force: true });
cy.url().should('include', '/apm/service-map');
it('navigates to Settings page', () => {
cy.visitKibana('/');
assertDeepLink(
keyword,
'Applications / Settings',
'/apm/settings/general-settings',
'bottom'
);
});
});
});
});

cy.waitUntilPageContentIsLoaded();
cy.getByTestSubj('nav-search-input').should('be.visible').type(keyword, { force: true });
// scroll to the bottom because results are not rendering otherwise
scrollToBottomResults();
// navigates to dependencies page
cy.contains('Applications / Dependencies').click({ force: true });
cy.url().should('include', '/apm/dependencies/inventory');
function assertDeepLink(
keyword: string,
title: string,
url: string,
scroll?: Cypress.PositionType
) {
// Wait until the page content is fully loaded
// otherwise, the search results may disappear before all checks are completed, making this test flaky
cy.waitUntilPageContentIsLoaded();
cy.getByTestSubj('nav-search-input').should('be.visible').type(keyword, { force: true });

cy.waitUntilPageContentIsLoaded();
cy.getByTestSubj('nav-search-input').should('be.visible').type(keyword, { force: true });
// scroll to the bottom because results are not rendering otherwise
scrollToBottomResults();
// navigates to settings page
cy.contains('Applications / Settings').click({ force: true });
cy.url().should('include', '/apm/settings/general-settings');
if (scroll) {
scrollToPositionResults(scroll);
}
});

function scrollToBottomResults() {
cy.getByTestSubj('euiSelectableList').find('div > div').scrollTo('bottom');
// Force click because welcome screen changes
// https://github.com/elastic/kibana/pull/108193
cy.contains(title).click({ force: true });
cy.url().should('include', url);
}

function scrollToPositionResults(position: Cypress.PositionType) {
// Make sure the search results are visible and we can scroll
cy.getByTestSubj('euiSelectableList')
.should('be.visible')
.find('div > div')
.should('have.length.greaterThan', 0)
.scrollTo(position);
}

0 comments on commit 45f3241

Please sign in to comment.