Skip to content

Commit

Permalink
[APM] Improve Cypress tests with sessions and better async handling (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Aug 23, 2022
1 parent 6f0bfcf commit 50821db
Show file tree
Hide file tree
Showing 29 changed files with 322 additions and 287 deletions.
5 changes: 4 additions & 1 deletion x-pack/plugins/apm/ftr_e2e/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
"screenshotsFolder": "./cypress/screenshots",
"supportFile": "./cypress/support/index.ts",
"videosFolder": "./cypress/videos",
"requestTimeout": 10000,
"responseTimeout": 40000,
"defaultCommandTimeout": 30000,
"execTimeout": 120000,
"pageLoadTimeout": 120000,
"viewportHeight": 900,
"viewportWidth": 1440,
"video": false,
"screenshotOnRunFailure": false
"screenshotOnRunFailure": false,
"experimentalSessionAndOrigin": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,55 @@ import { opbeans } from '../../../fixtures/synthtrace/opbeans';

const start = '2021-10-10T00:00:00.000Z';
const end = '2021-10-10T00:15:00.000Z';
describe.skip('Comparison feature flag', () => {
before(async () => {
await synthtrace.index(
describe('Comparison feature flag', () => {
before(() => {
synthtrace.index(
opbeans({
from: new Date(start).getTime(),
to: new Date(end).getTime(),
})
);
});

after(async () => {
await synthtrace.clean();
after(() => {
synthtrace.clean();
});

describe('when comparison feature is enabled', () => {
beforeEach(() => {
cy.loginAsEditorUser();

cy.updateAdvancedSettings({
'observability:enableComparisonByDefault': true,
});
});

it('shows the comparison feature enabled in services overview', () => {
cy.visit('/app/apm/services');
cy.visitKibana('/app/apm/services');
cy.get('input[type="checkbox"]#comparison').should('be.checked');
cy.get('[data-test-subj="comparisonSelect"]').should('not.be.disabled');
});

it('shows the comparison feature enabled in services overview', () => {
cy.visit('/app/apm/dependencies');
it('shows the comparison feature enabled in dependencies overview', () => {
cy.visitKibana('/app/apm/dependencies');
cy.get('input[type="checkbox"]#comparison').should('be.checked');
cy.get('[data-test-subj="comparisonSelect"]').should('not.be.disabled');
});

it('shows the comparison feature disabled in service map overview page', () => {
cy.visit('/app/apm/service-map');
cy.visitKibana('/app/apm/service-map');
cy.get('input[type="checkbox"]#comparison').should('be.checked');
cy.get('[data-test-subj="comparisonSelect"]').should('not.be.disabled');
});
});

describe('when comparison feature is disabled', () => {
beforeEach(() => {
cy.loginAsEditorUser().then(() => {
// Disables comparison feature on advanced settings
cy.updateAdvancedSettings({
'observability:enableComparisonByDefault': false,
});
cy.loginAsEditorUser();

// Disables comparison feature on advanced settings
cy.updateAdvancedSettings({
'observability:enableComparisonByDefault': false,
});
});

Expand All @@ -65,7 +69,7 @@ describe.skip('Comparison feature flag', () => {
});

it('shows the comparison feature disabled in services overview', () => {
cy.visit('/app/apm/services');
cy.visitKibana('/app/apm/services');
cy.get('input[type="checkbox"]#comparison').should('not.be.checked');
cy.get('[data-test-subj="comparisonSelect"]').should('be.disabled');
});
Expand All @@ -74,14 +78,14 @@ describe.skip('Comparison feature flag', () => {
cy.intercept('GET', '/internal/apm/dependencies/top_dependencies?*').as(
'topDependenciesRequest'
);
cy.visit('/app/apm/dependencies');
cy.wait('@topDependenciesRequest', { requestTimeout: 10000 });
cy.visitKibana('/app/apm/dependencies');
cy.wait('@topDependenciesRequest');
cy.get('input[type="checkbox"]#comparison').should('not.be.checked');
cy.get('[data-test-subj="comparisonSelect"]').should('be.disabled');
});

it('shows the comparison feature disabled in service map overview page', () => {
cy.visit('/app/apm/service-map');
cy.visitKibana('/app/apm/service-map');
cy.get('input[type="checkbox"]#comparison').should('not.be.checked');
cy.get('[data-test-subj="comparisonSelect"]').should('be.disabled');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ const nodeServiceInfraPageHref = url.format({
query: { rangeFrom: start, rangeTo: end },
});

describe.skip('Infrastructure page', () => {
before(async () => {
await synthtrace.index(
describe('Infrastructure page', () => {
before(() => {
synthtrace.index(
generateData({
from: new Date(start).getTime(),
to: new Date(end).getTime(),
})
);
});

after(async () => {
await synthtrace.clean();
after(() => {
synthtrace.clean();
});

beforeEach(() => {
Expand All @@ -47,15 +47,15 @@ describe.skip('Infrastructure page', () => {

describe('when data is loaded', () => {
it('has no detectable a11y violations on load', () => {
cy.visit(goServiceInfraPageHref);
cy.visitKibana(goServiceInfraPageHref);
cy.contains('Infrastructure');
// set skipFailures to true to not fail the test when there are accessibility failures
checkA11y({ skipFailures: true });
});

describe('when container ids, pod names and host names are returned by the api call', () => {
it('shows all tabs', () => {
cy.visit(goServiceInfraPageHref);
cy.visitKibana(goServiceInfraPageHref);
cy.contains('Containers');
cy.contains('Pods');
cy.contains('Hosts');
Expand All @@ -64,14 +64,14 @@ describe.skip('Infrastructure page', () => {

describe('when only host names are returned by the api call', () => {
it('shows only Hosts tab', () => {
cy.visit(javaServiceInfraPageHref);
cy.visitKibana(javaServiceInfraPageHref);
cy.contains('Hosts');
});
});

describe('when none infrastructure attributes are returned by the api call', () => {
it('shows no data message', () => {
cy.visit(nodeServiceInfraPageHref);
cy.visitKibana(nodeServiceInfraPageHref);
cy.contains('No results match your search criteria.');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe.skip('when navigating to integration page', () => {
const integrationsPath = '/app/integrations/browse';

cy.loginAsEditorUser();
cy.visit(integrationsPath);
cy.visitKibana(integrationsPath);

// open integration policy form
cy.get('[data-test-subj="integration-card:epr:apm:featured').click();
Expand All @@ -79,17 +79,17 @@ describe.skip('when navigating to integration page', () => {
});

it('should display Tail-based section on latest version', () => {
cy.visit('/app/fleet/integrations/apm/add-integration');
cy.visitKibana('/app/fleet/integrations/apm/add-integration');
cy.contains('Tail-based sampling').should('exist');
});

it('should hide Tail-based section for 8.0.0 apm package', () => {
cy.visit('/app/fleet/integrations/apm-8.0.0/add-integration');
cy.visitKibana('/app/fleet/integrations/apm-8.0.0/add-integration');
cy.contains('Tail-based sampling').should('not.exist');
});

it('should Display Debug section', () => {
cy.visit('/app/fleet/integrations/apm-8.0.0/add-integration');
cy.visitKibana('/app/fleet/integrations/apm-8.0.0/add-integration');
cy.contains('Debug settings').should('exist');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,55 @@
* 2.0.
*/

const apmIndicesSaveURL = '/internal/apm/settings/apm-indices/save';

describe('No data screen', () => {
describe('bypass no data screen on settings pages', () => {
beforeEach(() => {
cy.loginAsEditorUser();
});

before(() => {
// Change default indices
cy.request({
url: apmIndicesSaveURL,
method: 'POST',
body: {
sourcemap: 'foo-*',
error: 'foo-*',
onboarding: 'foo-*',
span: 'foo-*',
transaction: 'foo-*',
metric: 'foo-*',
},
headers: {
'kbn-xsrf': true,
},
auth: { user: 'editor', pass: 'changeme' },
// Change indices
setApmIndices({
sourcemap: 'foo-*',
error: 'foo-*',
onboarding: 'foo-*',
span: 'foo-*',
transaction: 'foo-*',
metric: 'foo-*',
});
});

beforeEach(() => {
cy.loginAsEditorUser();
});

it('shows no data screen instead of service inventory', () => {
cy.visit('/app/apm/');
cy.visitKibana('/app/apm/');
cy.contains('Welcome to Elastic Observability!');
});

it('shows settings page', () => {
cy.visit('/app/apm/settings');
cy.visitKibana('/app/apm/settings');
cy.contains('Welcome to Elastic Observability!').should('not.exist');
cy.get('h1').contains('Settings');
});

after(() => {
// reset to default indices
cy.request({
url: apmIndicesSaveURL,
method: 'POST',
body: {
sourcemap: '',
error: '',
onboarding: '',
span: '',
transaction: '',
metric: '',
},
headers: { 'kbn-xsrf': true },
auth: { user: 'editor', pass: 'changeme' },
setApmIndices({
sourcemap: '',
error: '',
onboarding: '',
span: '',
transaction: '',
metric: '',
});
});
});
});

function setApmIndices(body: Record<string, string>) {
cy.request({
url: '/internal/apm/settings/apm-indices/save',
method: 'POST',
body,
headers: { 'kbn-xsrf': true },
auth: { user: 'editor', pass: 'changeme' },
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
*/

function deleteAllRules() {
cy.log('Delete all rules');
cy.request({
log: false,
method: 'GET',
url: '/api/alerting/rules/_find',
auth: { user: 'editor', pass: 'changeme' },
}).then(({ body }) => {
if (body.data.length > 0) {
cy.log(`Deleting rules`);
Expand All @@ -21,12 +23,21 @@ function deleteAllRules() {
log: false,
method: 'DELETE',
url: `/api/alerting/rule/${id}`,
auth: { user: 'editor', pass: 'changeme' },
});
});
});
}

describe('Rules', () => {
beforeEach(() => {
deleteAllRules();
});

after(() => {
deleteAllRules();
});

describe('Error count', () => {
const ruleName = 'Error count threshold';
const comboBoxInputSelector =
Expand All @@ -36,18 +47,11 @@ describe('Rules', () => {

describe('when created from APM', () => {
describe('when created from Service Inventory', () => {
before(() => {
it('creates a rule', () => {
cy.loginAsEditorUser();
deleteAllRules();
});

after(() => {
deleteAllRules();
});

it('creates a rule', () => {
// Create a rule in APM
cy.visit('/app/apm/services');
cy.visitKibana('/app/apm/services');
cy.contains('Alerts and rules').click();
cy.contains('Create error count rule').click();

Expand All @@ -67,18 +71,13 @@ describe('Rules', () => {
});

describe('when created from Stack management', () => {
before(() => {
it('creates a rule', () => {
cy.loginAsEditorUser();
deleteAllRules();
});

after(() => {
deleteAllRules();
});

it('creates a rule', () => {
// Go to stack management
cy.visit('/app/management/insightsAndAlerting/triggersActions/rules');
cy.visitKibana(
'/app/management/insightsAndAlerting/triggersActions/rules'
);

// Create a rule
cy.contains('button', 'Create rule').click();
Expand Down
Loading

0 comments on commit 50821db

Please sign in to comment.