Skip to content
/ kibana Public
forked from elastic/kibana

Commit

Permalink
Re-enable and fix APM E2E tests
Browse files Browse the repository at this point in the history
* Run previously disabled APM E2E tests on all PRs (we were previously only running them when APM files had changes.)
* Remove `precise: true` from `getComparisonTypes` call which caused intermittent failures in date comparison tests.
* Simplify error count alert tests to test the "happy path" (elastic#79284 exists in order to expand to more tests for rule editing and creation)
* Wait for alert list API request to complete before clicking "Create rule" button when running the test to create a rule from the Stack Management UI.

I ran the e2e tests 100 times locally with no failures so I'm confident the flakiness has been addressed.

Fixes elastic#114419.
Fixes elastic#109205.
  • Loading branch information
smith committed Oct 13, 2021
1 parent 4f89393 commit 45ecc74
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,66 +20,56 @@ describe('Rules', () => {
describe('when created from Service Inventory', () => {
before(() => {
cy.loginAsPowerUser();
cy.deleteAllRules();
});

it('creates and updates a rule', () => {
after(() => {
cy.deleteAllRules();
});

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

// Change the environment to "testing"
cy.contains('Environment All').click();
cy.get(comboBoxInputSelector).type('testing{enter}');

// Save, with no actions
cy.contains('button:not(:disabled)', 'Save').click();
cy.get(confirmModalButtonSelector).click();

cy.contains(`Created rule "${ruleName}`);

// Go to Stack Management
cy.contains('Alerts and rules').click();
cy.contains('Manage rules').click();

// Edit the rule, changing the environment to "All"
cy.get(editButtonSelector).click();
cy.contains('Environment testing').click();
cy.get(comboBoxInputSelector).type('All{enter}');
cy.contains('button:not(:disabled)', 'Save').click();

cy.contains(`Updated '${ruleName}'`);

// Wait for the table to be ready for next edit click
cy.get('.euiBasicTable').not('.euiBasicTable-loading');

// Ensure the rule now shows "All" for the environment
cy.get(editButtonSelector).click();
cy.contains('Environment All');
cy.contains('button', 'Cancel').click();

// Delete the rule
cy.get(deleteButtonSelector).click();
cy.get(confirmModalButtonSelector).click();

// Ensure the table is empty
cy.contains('Create your first rule');
});
});
});

describe('when created from Stack management', () => {
before(() => {
cy.loginAsPowerUser();
cy.deleteAllRules();
cy.intercept(
'GET',
'/api/alerting/rules/_find?page=1&per_page=10&default_search_operator=AND&sort_field=name&sort_order=asc'
).as('list rules API call');
});

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

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

// Wait for this call to finish so the create rule button does not disappear.
// The timeout is set high because at this point we're also waiting for the
// full page load.
cy.wait('@list rules API call', { timeout: 30000 });

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

cy.get('[name=name]').type(ruleName);
cy.contains('.euiFlyout button', ruleName).click();

Expand All @@ -92,16 +82,6 @@ describe('Rules', () => {
cy.get(confirmModalButtonSelector).click();

cy.contains(`Created rule "${ruleName}`);

// Wait for the table to be ready for next delete click
cy.get('.euiBasicTable').not('.euiBasicTable-loading');

// Delete the rule
cy.get(deleteButtonSelector).click();
cy.get(confirmModalButtonSelector).click();

// Ensure the table is empty
cy.contains('Create your first rule');
});
});
});
Expand Down
16 changes: 16 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 @@ -7,6 +7,22 @@
import 'cypress-real-events/support';
import { Interception } from 'cypress/types/net-stubbing';

Cypress.Commands.add('deleteAllRules', () => {
cy.request('/api/alerting/rules/_find').then(({ body }) => {
if (body.data.length > 0) {
cy.log(`Deleting rules`);
}

body.data.map(({ id }) => {
cy.request({
headers: { 'kbn-xsrf': 'true' },
method: 'DELETE',
url: `/api/alerting/rule/${id}`,
});
});
});
});

Cypress.Commands.add('loginAsReadOnlyUser', () => {
cy.loginAs({ username: 'apm_read_user', password: 'changeme' });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export function getComparisonTypes({
start: momentStart,
end: momentEnd,
unitOfTime: 'days',
precise: true,
});

// Less than or equals to one day
Expand Down

0 comments on commit 45ecc74

Please sign in to comment.