Skip to content

Commit

Permalink
[APM] Add snapshots to visual regression tests (elastic#165834)
Browse files Browse the repository at this point in the history
Added snapshots to the service map e2e test and other improvements.

Due to flakiness of the visual regression tests, we leave them skipped,
and we can continue investigating, this issue
elastic#166050 was created with this
porpoise.

---------

Co-authored-by: Søren Louv-Jansen <soren.louv@elastic.co>
  • Loading branch information
MiriamAparicio and sorenlouv committed Sep 11, 2023
1 parent c6770af commit 1ada79e
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ npm-debug.log*
## @cypress/snapshot from apm plugin
/snapshots.js
/apm-diagnostics*.json
/x-pack/plugins/apm/ftr_e2e/cypress/e2e/service_map/snapshots/*.actual.png
/x-pack/plugins/apm/ftr_e2e/cypress/e2e/service_map/snapshots/*.diff.png

# transpiled cypress config
x-pack/plugins/fleet/cypress.config.d.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,48 @@ describe('service map', () => {
describe('when navigating to service map', () => {
beforeEach(() => {
cy.intercept('GET', '/internal/apm/service-map?*').as('serviceMap');
cy.visitKibana(serviceMapHref);
});

it.skip('shows nodes in service map', () => {
cy.visitKibana(serviceMapHref);
cy.wait('@serviceMap');
});
cy.getByTestSubj('apmServiceGroupsTourDismissButton').click();

prepareCanvasForScreenshot();

it('shows nodes in service map', { retries: 3 }, () => {
cy.wait(500);
cy.getByTestSubj('serviceMap').matchImage();
cy.withHidden('[data-test-subj="headerGlobalNav"]', () =>
cy.getByTestSubj('serviceMap').matchImage({
imagesPath: '{spec_path}/snapshots',
title: 'global_service_map',
matchAgainstPath: 'cypress/e2e/service_map/snapshots/service_map.png',
maxDiffThreshold: 0.02, // maximum threshold above which the test should fail
})
);
});

it('shows nodes in detailed service map', () => {
it.skip('shows nodes in detailed service map', () => {
cy.visitKibana(detailedServiceMap);
cy.wait('@serviceMap');
cy.contains('h1', 'opbeans-java');
cy.wait(500);
cy.getByTestSubj('serviceMap').matchImage();

prepareCanvasForScreenshot();

cy.withHidden('[data-test-subj="headerGlobalNav"]', () =>
cy.getByTestSubj('serviceMap').matchImage({
imagesPath: '{spec_path}/snapshots',
title: 'detailed_service_map',
matchAgainstPath:
'cypress/e2e/service_map/snapshots/detailed_service_map.png',
maxDiffThreshold: 0.02, // maximum threshold above which the test should fail
})
);
});

describe('when there is no data', () => {
it('shows empty state', () => {
cy.visitKibana(serviceMapHref);
// we need to dismiss the service-group call out first
cy.contains('Dismiss').click();
cy.getByTestSubj('apmServiceGroupsTourDismissButton').click();
cy.getByTestSubj('apmUnifiedSearchBar').type('_id : foo{enter}');
cy.contains('No services available');
// search bar is still visible
Expand All @@ -79,3 +100,15 @@ describe('service map', () => {
});
});
});

function prepareCanvasForScreenshot() {
cy.get('html, body').invoke(
'attr',
'style',
'height: auto; scroll-behavior: auto;'
);

cy.wait(300);
cy.getByTestSubj('centerServiceMap').click();
cy.scrollTo('top');
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions x-pack/plugins/apm/ftr_e2e/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ Cypress.Commands.add('dismissServiceGroupsTour', () => {
);
});

Cypress.Commands.add('withHidden', (selector, callback) => {
cy.get(selector).invoke('attr', 'style', 'display: none');
callback();
cy.get(selector).invoke('attr', 'style', '');
});

// A11y configuration

const axeConfig = {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/ftr_e2e/cypress/support/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ declare namespace Cypress {
updateAdvancedSettings(settings: Record<string, unknown>): void;
getByTestSubj(selector: string): Chainable<JQuery<Element>>;
dismissServiceGroupsTour(): void;
withHidden(selector: string, callback: () => void): void;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export function Controls() {
<Panel hasShadow={true} paddingSize="none">
<EuiToolTip anchorClassName="eui-displayInline" content={centerLabel}>
<Button
data-test-subj="centerServiceMap"
aria-label={centerLabel}
color="text"
iconType="crosshairs"
Expand Down

0 comments on commit 1ada79e

Please sign in to comment.