Skip to content

Commit

Permalink
add benchmark tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gurevichdmitry committed Jul 2, 2024
1 parent db5ff40 commit c7aa20c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../ftr_provider_context';

// eslint-disable-next-line import/no-default-export
export default ({ getPageObjects, getService }: FtrProviderContext) => {
const pageObjects = getPageObjects(['common', 'benchmark']);

describe('Benchmark Page', function () {
this.tags(['cloud_security_posture_ui_sanity']);
let benchmark: typeof pageObjects.benchmark;

before(async () => {
benchmark = pageObjects.benchmark;
await benchmark.navigateToBenchnmarkPage();
await benchmark.waitForPluginInitialized();
});

it('Benchmark table exists', async () => {
expect(await benchmark.benchmarkPage.doesBenchmarkTableExists());
});

it('Benchmarks count is more than 0', async () => {
const benchmarksRows = await benchmark.benchmarkPage.getBenchmarkTableRows();
expect(benchmarksRows.length).to.be.greaterThan(0);
});

it('For each benchmark, evaluation and complience are not empty', async () => {
const benchmarksRows = await benchmark.benchmarkPage.getBenchmarkTableRows();
for (const row of benchmarksRows) {
const benchmarkName = await benchmark.benchmarkPage.getCisNameCellData(row);
const evaluated = await benchmark.benchmarkPage.getEvaluatedCellData(row);
const compliance = await benchmark.benchmarkPage.getComplianceCellData(row);
expect(await evaluated).to.not.contain(
'Add',
`The ${benchmarkName} does not have evaluated data`
);
expect(await compliance).to.not.contain(
'No',
`The ${benchmarkName} does not have compliance data`
);
}
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { FtrProviderContext } from '../ftr_provider_context';
// eslint-disable-next-line import/no-default-export
export default ({ getPageObjects, getService }: FtrProviderContext) => {
const retry = getService('retry');
const pageObjects = getPageObjects(['common', 'cloudPostureDashboard', 'header']);
const pageObjects = getPageObjects(['common', 'cloudPostureDashboard', 'header', 'benchmark']);

describe('Cloud Posture Dashboard Page', function () {
this.tags(['cloud_security_posture_ui_sanity']);
Expand Down Expand Up @@ -46,11 +46,11 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
expect(scores.length).to.be(4);
});

it('displays a number of resources evaluated greater than 3000', async () => {
it('displays a number of resources evaluated greater than 2000', async () => {
const resourcesEvaluated = await dashboard.getCloudResourcesEvaluated();
const visibleText = await resourcesEvaluated.getVisibleText();
const resourcesEvaluatedCount = parseInt(visibleText.replace(/,/g, ''), 10);
expect(resourcesEvaluatedCount).greaterThan(3000);
expect(resourcesEvaluatedCount).greaterThan(2000);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FtrProviderContext } from '../ftr_provider_context';
// eslint-disable-next-line import/no-default-export
export default function ({ loadTestFile }: FtrProviderContext) {
describe('Cloud Security Posture', function () {
loadTestFile(require.resolve('./basic_ui_sanity'));
loadTestFile(require.resolve('./dashboard_sanity'));
loadTestFile(require.resolve('./benchmark_sanity'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ export function BenchmarkPagePageProvider({ getService, getPageObjects }: FtrPro
doesBenchmarkTableExists: async () => {
return await testSubjects.find('csp_benchmarks_table');
},

getBenchmarkTableRows: async () => {
const benchmarkTable = await testSubjects.find(CSP_BECNHMARK_TABLE);
return await benchmarkTable.findAllByXpath(`//tbody//tr`);
},

getCellData: async (row: any, cellDataTestSubj: string) => {
const cell = await row.findByTestSubject(cellDataTestSubj);
return await cell.getVisibleText();
},

getEvaluatedCellData: async (row: any) => {
return await benchmarkPage.getCellData(row, 'benchmark-table-column-evaluated');
},

getComplianceCellData: async (row: any) => {
return await benchmarkPage.getCellData(row, 'benchmark-table-column-compliance');
},

getCisNameCellData: async (row: any) => {
return await benchmarkPage.getCellData(row, 'benchmark-table-column-cis-name');
},
};

const navigateToBenchnmarkPage = async () => {
Expand Down

0 comments on commit c7aa20c

Please sign in to comment.