[APM] Fix Deep Links Cypress Flaky Test (#206000)

## Summary

Closes https://github.com/elastic/kibana/issues/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
This commit is contained in:
Sergi Romeu 2025-01-09 14:54:11 +01:00 committed by GitHub
parent 49690d7a11
commit 45f3241db0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 });
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');
});
it('navigates to Service Inventory page', () => {
cy.visitKibana('/');
assertDeepLink(keyword, 'Applications / Service Inventory', '/apm/services');
});
it('navigates to Service groups page', () => {
cy.visitKibana('/');
assertDeepLink(keyword, 'Applications / Service groups', '/apm/service-groups');
});
it('navigates to Traces page', () => {
cy.visitKibana('/');
assertDeepLink(keyword, 'Applications / Traces', '/apm/traces', 'center');
});
it('navigates to Service Map page', () => {
cy.visitKibana('/');
assertDeepLink(keyword, 'Applications / Service Map', '/apm/service-map', 'center');
});
it('navigates to Dependencies page', () => {
cy.visitKibana('/');
assertDeepLink(
keyword,
'Applications / Dependencies',
'/apm/dependencies/inventory',
'bottom'
);
});
it('navigates to Settings page', () => {
cy.visitKibana('/');
assertDeepLink(
keyword,
'Applications / Settings',
'/apm/settings/general-settings',
'bottom'
);
});
});
});
it('navigates to Application links on "apm" search', () => {
cy.visitKibana('/');
navigatesToApmLinks('apm');
});
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');
// 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');
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');
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');
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');
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');
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');
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');
}
});
function scrollToBottomResults() {
cy.getByTestSubj('euiSelectableList').find('div > div').scrollTo('bottom');
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 });
if (scroll) {
scrollToPositionResults(scroll);
}
// 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);
}