Skip to content

Commit

Permalink
[APM] Refactor Cypress e2e tests (#109024)
Browse files Browse the repository at this point in the history
* Improve script to setup users and roles

* fix readme

* CI fixes

* add index permissions to roles

* disable welcome screen

* Run es archive once before tests

* Fix ts issues

* Update x-pack/plugins/apm/readme.md

Co-authored-by: Nathan L Smith <nathan.smith@elastic.co>

Co-authored-by: Nathan L Smith <nathan.smith@elastic.co>
  • Loading branch information
sorenlouv and smith authored Aug 19, 2021
1 parent d522cae commit a93a7ef
Show file tree
Hide file tree
Showing 33 changed files with 453 additions and 413 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/apm/ftr_e2e/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async function config({ readConfigFile }: FtrConfigProviderContext) {
...xpackFunctionalTestsConfig.get('kbnTestServer'),
serverArgs: [
...xpackFunctionalTestsConfig.get('kbnTestServer.serverArgs'),
'--home.disableWelcomeScreen=true',
'--csp.strict=false',
// define custom kibana server args here
`--elasticsearch.ssl.certificateAuthorities=${CA_CERT_PATH}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import url from 'url';
import archives_metadata from '../../fixtures/es_archiver/archives_metadata';
import { esArchiverLoad, esArchiverUnload } from '../../tasks/es_archiver';

const { start, end } = archives_metadata['apm_8.0.0'];

Expand All @@ -28,15 +27,10 @@ const apisToIntercept = [
];

describe('Home page', () => {
before(() => {
esArchiverLoad('apm_8.0.0');
});
after(() => {
esArchiverUnload('apm_8.0.0');
});
beforeEach(() => {
cy.loginAsReadOnlyUser();
});

it('Redirects to service page with rangeFrom and rangeTo added to the URL', () => {
cy.visit('/app/apm');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
import url from 'url';
import archives_metadata from '../../../fixtures/es_archiver/archives_metadata';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';

const { start, end } = archives_metadata['apm_8.0.0'];

Expand Down Expand Up @@ -59,15 +58,10 @@ const apisToIntercept = [
];

describe('Service overview - header filters', () => {
before(() => {
esArchiverLoad('apm_8.0.0');
});
after(() => {
esArchiverUnload('apm_8.0.0');
});
beforeEach(() => {
cy.loginAsReadOnlyUser();
});

describe('Filtering by transaction type', () => {
it('changes url when selecting different value', () => {
cy.visit(serviceOverviewHref);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import url from 'url';
import archives_metadata from '../../../fixtures/es_archiver/archives_metadata';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';

const { start, end } = archives_metadata['apm_8.0.0'];

Expand Down Expand Up @@ -43,25 +42,21 @@ describe('Instances table', () => {
beforeEach(() => {
cy.loginAsReadOnlyUser();
});
describe('when data is not loaded', () => {
it('shows empty message', () => {
cy.visit(serviceOverviewHref);
cy.contains('opbeans-java');
cy.get('[data-test-subj="serviceInstancesTableContainer"]').contains(
'No items found'
);
});
});

// describe('when data is not loaded', () => {
// it('shows empty message', () => {
// cy.visit(serviceOverviewHref);
// cy.contains('opbeans-java');
// cy.get('[data-test-subj="serviceInstancesTableContainer"]').contains(
// 'No items found'
// );
// });
// });

describe('when data is loaded', () => {
before(() => {
esArchiverLoad('apm_8.0.0');
});
after(() => {
esArchiverUnload('apm_8.0.0');
});
const serviceNodeName =
'31651f3c624b81c55dd4633df0b5b9f9ab06b151121b0404ae796632cd1f87ad';

it('has data in the table', () => {
cy.visit(serviceOverviewHref);
cy.contains('opbeans-java');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import url from 'url';
import archives_metadata from '../../../fixtures/es_archiver/archives_metadata';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';

const { start, end } = archives_metadata['apm_8.0.0'];

Expand All @@ -18,15 +17,10 @@ const baseUrl = url.format({
});

describe('Service Overview', () => {
before(() => {
esArchiverLoad('apm_8.0.0');
});
after(() => {
esArchiverUnload('apm_8.0.0');
});
beforeEach(() => {
cy.loginAsReadOnlyUser();
});

it('persists transaction type selected when clicking on Transactions tab', () => {
cy.visit(baseUrl);
cy.get('[data-test-subj="headerFilterTransactionType"]').should(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import url from 'url';
import moment from 'moment';
import archives_metadata from '../../../fixtures/es_archiver/archives_metadata';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';

const { start, end } = archives_metadata['apm_8.0.0'];

Expand Down Expand Up @@ -47,12 +46,6 @@ const apisToIntercept = [
];

describe('Service overview: Time Comparison', () => {
before(() => {
esArchiverLoad('apm_8.0.0');
});
after(() => {
esArchiverUnload('apm_8.0.0');
});
beforeEach(() => {
cy.loginAsReadOnlyUser();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import url from 'url';
import archives_metadata from '../../../fixtures/es_archiver/archives_metadata';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';

const { start, end } = archives_metadata['apm_8.0.0'];

Expand All @@ -17,15 +16,10 @@ const serviceOverviewHref = url.format({
});

describe('Transactions Overview', () => {
before(() => {
esArchiverLoad('apm_8.0.0');
});
after(() => {
esArchiverUnload('apm_8.0.0');
});
beforeEach(() => {
cy.loginAsReadOnlyUser();
});

it('persists transaction type selected when navigating to Overview tab', () => {
cy.visit(serviceOverviewHref);
cy.get('[data-test-subj="headerFilterTransactionType"]').should(
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/apm/ftr_e2e/cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@
* 2.0.
*/

Cypress.on('uncaught:exception', (err, runnable) => {
// @see https://stackoverflow.com/a/50387233/434980
// ResizeObserver error can be safely ignored
if (err.message.includes('ResizeObserver loop limit exceeded')) {
return false;
}
});

import './commands';
15 changes: 8 additions & 7 deletions x-pack/plugins/apm/ftr_e2e/cypress/tasks/es_archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,32 @@
*/

import Path from 'path';
import { execSync } from 'child_process';

const ES_ARCHIVE_DIR = './cypress/fixtures/es_archiver';

// Otherwise cy.exec would inject NODE_TLS_REJECT_UNAUTHORIZED=0 and node would abort if used over https
// Otherwise execSync would inject NODE_TLS_REJECT_UNAUTHORIZED=0 and node would abort if used over https
const NODE_TLS_REJECT_UNAUTHORIZED = '1';

export const esArchiverLoad = (folder: string) => {
const path = Path.join(ES_ARCHIVE_DIR, folder);
cy.exec(
execSync(
`node ../../../../scripts/es_archiver load "${path}" --config ../../../test/functional/config.js`,
{ env: { NODE_TLS_REJECT_UNAUTHORIZED } }
{ env: { ...process.env, NODE_TLS_REJECT_UNAUTHORIZED } }
);
};

export const esArchiverUnload = (folder: string) => {
const path = Path.join(ES_ARCHIVE_DIR, folder);
cy.exec(
execSync(
`node ../../../../scripts/es_archiver unload "${path}" --config ../../../test/functional/config.js`,
{ env: { NODE_TLS_REJECT_UNAUTHORIZED } }
{ env: { ...process.env, NODE_TLS_REJECT_UNAUTHORIZED } }
);
};

export const esArchiverResetKibana = () => {
cy.exec(
execSync(
`node ../../../../scripts/es_archiver empty-kibana-index --config ../../../test/functional/config.js`,
{ env: { NODE_TLS_REJECT_UNAUTHORIZED }, failOnNonZeroExit: false }
{ env: { ...process.env, NODE_TLS_REJECT_UNAUTHORIZED } }
);
};
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/ftr_e2e/cypress_open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { FtrConfigProviderContext } from '@kbn/test';
import { cypressOpenTests } from './cypress_start';

async function openE2ETests({ readConfigFile }: FtrConfigProviderContext) {
const cypressConfig = await readConfigFile(require.resolve('./config.ts'));
const kibanaConfig = await readConfigFile(require.resolve('./config.ts'));
return {
...cypressConfig.getAll(),
...kibanaConfig.getAll(),
testRunner: cypressOpenTests,
};
}
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/apm/ftr_e2e/cypress_run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { argv } from 'yargs';
import { FtrConfigProviderContext } from '@kbn/test';
import { cypressRunTests } from './cypress_start';

const spec = argv.grep as string;
const specArg = argv.spec as string | undefined;

async function runE2ETests({ readConfigFile }: FtrConfigProviderContext) {
const cypressConfig = await readConfigFile(require.resolve('./config.ts'));
const kibanaConfig = await readConfigFile(require.resolve('./config.ts'));
return {
...cypressConfig.getAll(),
testRunner: cypressRunTests(spec),
...kibanaConfig.getAll(),
testRunner: cypressRunTests(specArg),
};
}

Expand Down
15 changes: 11 additions & 4 deletions x-pack/plugins/apm/ftr_e2e/cypress_start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Url from 'url';
import cypress from 'cypress';
import { FtrProviderContext } from './ftr_provider_context';
import archives_metadata from './cypress/fixtures/es_archiver/archives_metadata';
import { createKibanaUserRole } from '../scripts/kibana-security/create_kibana_user_role';
import { createApmUsersAndRoles } from '../scripts/create-apm-users-and-roles/create_apm_users_and_roles';
import { esArchiverLoad, esArchiverUnload } from './cypress/tasks/es_archiver';

export function cypressRunTests(spec?: string) {
return async ({ getService }: FtrProviderContext) => {
Expand Down Expand Up @@ -47,7 +48,7 @@ async function cypressStart(
});

// Creates APM users
await createKibanaUserRole({
await createApmUsersAndRoles({
elasticsearch: {
username: config.get('servers.elasticsearch.username'),
password: config.get('servers.elasticsearch.password'),
Expand All @@ -58,13 +59,19 @@ async function cypressStart(
},
});

return cypressExecution({
...(spec !== 'undefined' ? { spec } : {}),
await esArchiverLoad('apm_8.0.0');

const res = await cypressExecution({
...(spec !== undefined ? { spec } : {}),
config: { baseUrl: kibanaUrl },
env: {
START_DATE: start,
END_DATE: end,
KIBANA_URL: kibanaUrl,
},
});

await esArchiverUnload('apm_8.0.0');

return res;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function ErrorGroupList({ items, serviceName }: Props) {
return (
<ManagedTable
noItemsMessage={i18n.translate('xpack.apm.errorsTable.noErrorsLabel', {
defaultMessage: 'No errors were found',
defaultMessage: 'No errors found',
})}
items={items}
columns={columns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ export function ServiceOverviewErrorsTable({ serviceName }: Props) {
}
>
<EuiBasicTable
noItemsMessage={
status === FETCH_STATUS.LOADING
? i18n.translate(
'xpack.apm.serviceOverview.errorsTable.loading',
{ defaultMessage: 'Loading...' }
)
: i18n.translate(
'xpack.apm.serviceOverview.errorsTable.noResults',
{ defaultMessage: 'No errors found' }
)
}
columns={columns}
items={items}
pagination={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ export function ServiceOverviewInstancesTable({
isEmptyAndLoading={mainStatsItemCount === 0 && isLoading}
>
<EuiBasicTable
noItemsMessage={
isLoading
? i18n.translate('xpack.apm.serviceOverview.loadingText', {
defaultMessage: 'No instances found',
})
: i18n.translate('xpack.apm.serviceOverview.noResultsText', {
defaultMessage: 'No instances found',
})
}
data-test-subj="instancesTable"
loading={isLoading}
items={mainStatsItems}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import { EuiBasicTable, EuiBasicTableColumn } from '@elastic/eui';
import { orderBy } from 'lodash';
import React, { ReactNode, useCallback, useMemo } from 'react';
Expand Down Expand Up @@ -129,7 +130,13 @@ function UnoptimizedManagedTable<T>(props: Props<T>) {
return (
<EuiBasicTable
loading={isLoading}
noItemsMessage={noItemsMessage}
noItemsMessage={
isLoading
? i18n.translate('xpack.apm.managedTable.loading', {
defaultMessage: 'Loading...',
})
: noItemsMessage
}
items={renderedItems}
columns={(columns as unknown) as Array<EuiBasicTableColumn<T>>} // EuiBasicTableColumn is stricter than ITableColumn
sorting={sort}
Expand Down
Loading

0 comments on commit a93a7ef

Please sign in to comment.