-
Notifications
You must be signed in to change notification settings - Fork 19
Logging-ui-plugin test using real data #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,130 @@ | ||
| import { defineConfig } from 'cypress'; | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const report_dir = process.env.ARTIFACT_DIR || '/tmp'; | ||
|
|
||
| export default defineConfig({ | ||
| screenshotsFolder: path.join(report_dir, 'cypress', 'screenshots'), | ||
| screenshotOnRunFailure: true, | ||
| trashAssetsBeforeRuns: true, | ||
| videosFolder: path.join(report_dir, 'cypress', 'videos'), | ||
| video: true, | ||
| videoCompression: false, | ||
| reporter: './node_modules/cypress-multi-reporters', | ||
| reporterOptions: { | ||
| reporterEnabled: 'mocha-junit-reporter, mochawesome', | ||
| mochaJunitReporterReporterOptions: { | ||
| mochaFile: path.join(report_dir, 'junit_cypress-[hash].xml'), | ||
| toConsole: false | ||
| }, | ||
| mochawesomeReporterOptions: { | ||
| reportDir: report_dir, | ||
| reportFilename: 'cypress_report', | ||
| overwrite: false, | ||
| html: false, | ||
| json: true | ||
| } | ||
| }, | ||
| env: { | ||
| grepFilterSpecs: false, | ||
| 'KUBECONFIG_PATH': process.env.KUBECONFIG, | ||
| 'NOO_CS_IMAGE': process.env.MULTISTAGE_PARAM_OVERRIDE_CYPRESS_NOO_CS_IMAGE, | ||
| 'OPENSHIFT_VERSION': process.env.CYPRESS_OPENSHIFT_VERSION, | ||
| }, | ||
| fixturesFolder: 'fixtures', | ||
| defaultCommandTimeout: 30000, | ||
| retries: { | ||
| runMode: 0, | ||
| openMode: 0, | ||
| }, | ||
| viewportWidth: 1600, | ||
| viewportHeight: 1200, | ||
| e2e: { | ||
| baseUrl: 'http://localhost:9003', | ||
| baseUrl: process.env.CYPRESS_BASE_URL || process.env.BASE_URL || 'http://localhost:9003', | ||
| setupNodeEvents(on, config) { | ||
| // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
| require('@cypress/code-coverage/task')(on, config); | ||
| on('before:browser:launch', (browser = { | ||
| name: "", | ||
| family: "chromium", | ||
| channel: "", | ||
| displayName: "", | ||
| version: "", | ||
| majorVersion: "", | ||
| path: "", | ||
| isHeaded: false, | ||
| isHeadless: false | ||
| }, launchOptions) => { | ||
| if (browser.family === 'chromium' && browser.name !== 'electron') { | ||
| // auto open devtools | ||
| launchOptions.args.push('--enable-precise-memory-info') | ||
| } | ||
|
|
||
| return launchOptions | ||
|
|
||
| }); | ||
| // `on` is used to hook into various events Cypress emits | ||
| on('task', { | ||
| log(message) { | ||
| console.log(message); | ||
| return null; | ||
| }, | ||
| logError(message) { | ||
| console.error(message); | ||
| return null; | ||
| }, | ||
| logTable(data) { | ||
| console.table(data); | ||
| return null; | ||
| }, | ||
| readFileIfExists(filename) { | ||
| if (fs.existsSync(filename)) { | ||
| return fs.readFileSync(filename, 'utf8'); | ||
| } | ||
| return null; | ||
| }, | ||
| }); | ||
| on('after:screenshot', (details) => { | ||
| // Prepend "1_", "2_", etc. to screenshot filenames because they are sorted alphanumerically in CI's artifacts dir | ||
| const pathObj = path.parse(details.path); | ||
| fs.readdir(pathObj.dir, (error, files) => { | ||
| const newPath = `${pathObj.dir}${path.sep}${files.length}_${pathObj.base}`; | ||
| return new Promise((resolve, reject) => { | ||
| // eslint-disable-next-line consistent-return | ||
| fs.rename(details.path, newPath, (err) => { | ||
| if (err) return reject(err); | ||
| // because we renamed and moved the image, resolve with the new path | ||
| // so it is accurate in the test results | ||
| resolve({ path: newPath }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| on( | ||
| 'after:spec', | ||
| (spec: Cypress.Spec, results: CypressCommandLine.RunResult) => { | ||
| if (results && results.video) { | ||
| // Do we have failures for any retry attempts? | ||
| const failures = results.tests.some((test) => | ||
| test.attempts.some((attempt) => attempt.state === 'failed') | ||
| ) | ||
| if (!failures && fs.existsSync(results.video)) { | ||
| // delete the video if the spec passed and no tests retried | ||
| fs.unlinkSync(results.video) | ||
| } | ||
| } | ||
| } | ||
| ); | ||
| require('@cypress/grep/src/plugin')(config); | ||
| return config; | ||
| }, | ||
| supportFile: './cypress/support/e2e.ts', | ||
| specPattern: './cypress/e2e/**/*.cy.{js,jsx,ts,tsx}', | ||
| numTestsKeptInMemory: 1, | ||
| testIsolation: false, | ||
| experimentalModifyObstructiveThirdPartyCode: true, | ||
| experimentalOriginDependencies: true, | ||
| experimentalMemoryManagement: true, | ||
| experimentalCspAllowList: ['default-src', 'script-src'] | ||
| }, | ||
| video: false, | ||
| viewportWidth: 1400, | ||
| }); | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import { TestIds } from '../../../src/test-ids'; | ||
| import { commonTests } from './logs-common-test.cy.ts'; | ||
| import { APP_NAMESPACE1,APP_NAMESPACE2,APP_MESSAGE } from './logs-common-test.cy.ts'; | ||
|
|
||
| describe('Admin in AdminConsole AggregatedLogs', () => { | ||
| before( function() { | ||
| cy.uiLoginAsClusterAdmin("first_user"); | ||
| cy.switchToAdmConsole(); | ||
| cy.get('button[data-quickstart-id="qs-nav-workloads"]').click(); | ||
| }); | ||
|
|
||
| beforeEach( function() { | ||
| //Hover on WorkLoad -> Pods page | ||
| cy.get('[id="page-sidebar"]') | ||
| .within(() => { | ||
| cy.contains('a[data-test="nav"]', 'Pods').click(); | ||
| }) | ||
| }); | ||
|
|
||
| after( function() { | ||
| //cy.uiLogoutClusterAdmin("first_user"); | ||
| }); | ||
|
|
||
| it('Log Panel top elements', {tags:['@smoke','@aggr']} , () => { | ||
| //load Aggregated Logs for the first pod in APP_NAMESPACE1 | ||
| cy.get('[data-test-id="namespace-bar-dropdown"]') | ||
| .find('button[aria-expanded="false"]') | ||
| .click(); | ||
|
|
||
| cy.get('[data-test="namespace-dropdown-menu"]') | ||
| .within(() => { | ||
| cy.contains('button', `${APP_NAMESPACE1}`).click(); | ||
| }); | ||
|
|
||
| cy.get('tr[data-test-rows="resource-row"]') | ||
| .first() | ||
| .find('td') | ||
| .first() | ||
| .find('a.co-resource-item__resource-name') | ||
| .click(); | ||
| cy.get('a[data-test-id="horizontal-link-Aggregated Logs"]').click(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as @jgbernalp had mentioned before, these data-test-id, data-id (when MaterialUI if Logging also uses), and other locators could be also be in the same /src/test-ids file in another "json object" like DataTestIds, DataIds, Classes, then according to the type you can create different selectors cy.getByDataTestId, cy.getByDataIds, cy.getByClasses and refer to them. When handling with Classes, you can refer both pf5 and pf6. You can take a look at this file as example: https://github.com/openshift/monitoring-plugin/blob/main/web/src/components/data-test.ts
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion. Let me define similar data-test.ts for Logging. |
||
|
|
||
| cy.getByTestId(TestIds.ToggleHistogramButton).should('exist'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. an example of reusable steps would be these assertions cross different user types or cross different pages, for example Logs and Aggregated Logs probably have many common components. This way, if something breaks one of the pages by any reason, you could also detect and fix it easily in one place. I didn't take a look at all cypress test files, but I have a feeling they are very similar in general and maybe one or another difference depending on the page (Logs or Agg Logs) and/or per user type. So, these steps could become more than reused.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it would be a pain now to refactor, decouple all these steps, but I am sure it worth as a short/mid/long term, specially if you need to backport all these files of 2 Logging versions and/or upgrade patternfly from 4/5 to 6 and future ones.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had defined a common function in this cypress/e2e/logging/logs-common-test.cy.ts which can be called in different page. |
||
| cy.getByTestId(TestIds.TimeRangeDropdown).should('exist'); | ||
| cy.getByTestId(TestIds.RefreshIntervalDropdown).should('exist'); | ||
| cy.getByTestId(TestIds.SyncButton).should('exist'); | ||
| cy.getByTestId(TestIds.AvailableAttributes).should('exist'); | ||
| cy.getByTestId(TestIds.SeverityDropdown).should('exist'); | ||
| cy.getByTestId(TestIds.TenantToggle).should('not.exist'); | ||
| cy.contains('button', 'Show Resources').should('exist'); | ||
| cy.getByTestId(TestIds.ShowStatsToggle).should('exist'); | ||
| cy.contains('button', 'Export as CSV').should('exist'); | ||
| cy.getByTestId(TestIds.ExecuteVolumeButton).should('exist'); | ||
| cy.getByTestId(TestIds.ExecuteQueryButton).should('exist'); | ||
| cy.getByTestId(TestIds.ShowQueryToggle).should('exist'); | ||
| cy.getByTestId(TestIds.LogsTable).should('exist'); | ||
| if (String(Cypress.env('CLUSTERLOGGING_DATAMODE')) == "select" ) { | ||
| cy.getByTestId(TestIds.SchemaToggle).should('exist'); | ||
| } | ||
| cy.getByTestId(TestIds.AttributeFilters).within(() => { | ||
| cy.getByTestId(TestIds.AvailableAttributes).click(); | ||
| cy.contains('li', 'Content'); | ||
| cy.contains('li', 'Namespaces').should('not.exist'); | ||
| cy.contains('li', 'Pod'); | ||
| cy.contains('li', 'Containers'); | ||
| }); | ||
| }); | ||
|
|
||
| it('admin can display applicatioins logs',{tags:['@smoke', '@aggr']}, () => { | ||
| //load Aggregated Logs for the first pod in APP_NAMESPACE1 | ||
| cy.get('[data-test-id="namespace-bar-dropdown"]') | ||
| .find('button[aria-expanded="false"]') | ||
| .click(); | ||
|
|
||
| cy.get('[data-test="namespace-dropdown-menu"]') | ||
| .within(() => { | ||
| cy.contains('button', `${APP_NAMESPACE1}`).click(); | ||
| }); | ||
|
|
||
| cy.get('section.pf-v6-c-page__main-section') | ||
| .contains('h1','Pods'); | ||
| cy.get('section[id="content-scrollable"]') | ||
| .within(() => { | ||
| cy.get('tr[data-test-rows="resource-row"]') | ||
| .first() | ||
| .find('td') | ||
| .first() | ||
| .find('a.co-resource-item__resource-name') | ||
| .click(); | ||
| }); | ||
| cy.get('a[data-test-id="horizontal-link-Aggregated Logs"]').click(); | ||
| cy.getByTestId(TestIds.LogsTable,{ timeout: 20000 }).should('be.visible'); | ||
| cy.assertLogInLogsTable(); | ||
| }); | ||
|
|
||
| it('admin can display infra container logs',{tags:['@smoke','@aggr']}, () => { | ||
| //load Aggregated Logs for pod in openshift-monitoring | ||
| cy.get('[data-test-id="namespace-bar-dropdown"]') | ||
| .find('button[aria-expanded="false"]') | ||
| .click(); | ||
| cy.get('input[data-test="dropdown-text-filter"]').type('openshift-monitoring'); | ||
| cy.get('input[data-test="showSystemSwitch"]').then($el => { | ||
| if ($el.attr('data-checked-state') === 'false') { | ||
| cy.wrap($el).click(); | ||
| } | ||
| }); | ||
| cy.get('[data-test="dropdown-menu-item-link"]',{ timeout: 6000 }) | ||
| .contains('button', 'openshift-monitoring') | ||
| .click(); | ||
| cy.get('section.pf-v6-c-page__main-section') | ||
| .contains('h1','Pods'); | ||
| //Click the pod alertmanager-main-0 | ||
| cy.get('tbody[role="rowgroup"]') | ||
| .find('a[data-test-id="alertmanager-main-0"]') | ||
| .click(); | ||
| //click Aggregated Logs tab | ||
| cy.get('a[data-test-id="horizontal-link-Aggregated Logs"]').click(); | ||
| cy.getByTestId(TestIds.LogsTable,{ timeout: 20000 }).should('be.visible'); | ||
| cy.assertLogInLogsTable(); | ||
| }); | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import { TestIds } from '../../../src/test-ids'; | ||
| import { commonTests } from './logs-common-test.cy.ts'; | ||
| import { APP_NAMESPACE1,APP_NAMESPACE2,APP_MESSAGE } from './logs-common-test.cy.ts'; | ||
|
|
||
| describe('Impersonate User in AdminConsole AggregatedLogs', () => { | ||
| before( function() { | ||
| cy.cliLogin("second_user") | ||
| cy.grantLogRoles("second_user", `${APP_NAMESPACE1}`); | ||
| cy.grantLogRoles("second_user", `${APP_NAMESPACE2}`); | ||
| cy.uiLoginAsClusterAdmin("first_user"); | ||
| cy.switchToAdmConsole(); | ||
| cy.uiImpersonateUser("second_user"); | ||
| cy.switchToAdmConsole(); | ||
| cy.get('button[data-quickstart-id="qs-nav-workloads"]').click(); | ||
| }); | ||
|
|
||
| beforeEach( function() { | ||
| //reload Aggregated Logs for first pod in APP_NAMESPACE1 | ||
| cy.get('[id="page-sidebar"]') | ||
| .within(() => { | ||
| cy.contains('a[data-test="nav"]', 'Pods').click(); | ||
| }) | ||
| cy.get('[data-test-id="namespace-bar-dropdown"]') | ||
| .find('button[aria-expanded="false"]') | ||
| .click(); | ||
|
|
||
| cy.get('[data-test="namespace-dropdown-menu"]') | ||
| .within(() => { | ||
| cy.contains('button', `${APP_NAMESPACE1}`).click(); | ||
| }); | ||
| cy.get('section.pf-v6-c-page__main-section') | ||
| .contains('h1','Pods'); | ||
| cy.get('section[id="content-scrollable"]') | ||
| .within(() => { | ||
| cy.get('tr[data-test-rows="resource-row"]') | ||
| .first() | ||
| .find('td') | ||
| .first() | ||
| .find('a.co-resource-item__resource-name') | ||
| .click(); | ||
| }); | ||
| cy.get('a[data-test-id="horizontal-link-Aggregated Logs"]').click(); | ||
| cy.getByTestId(TestIds.LogsTable,{ timeout: 20000 }).should('be.visible'); | ||
| }); | ||
|
|
||
| after( function() { | ||
| cy.uiLogoutUser("second_user"); | ||
| cy.removeLogRoles("second_user", `${APP_NAMESPACE1}`); | ||
| cy.removeLogRoles("second_user", `${APP_NAMESPACE2}`); | ||
| }); | ||
|
|
||
| it('validate elements in Aggregated Logs',{tags:['@smoke', '@aggr']}, () => { | ||
| cy.getByTestId(TestIds.ToggleHistogramButton).should('exist'); | ||
| cy.getByTestId(TestIds.TimeRangeDropdown).should('exist'); | ||
| cy.getByTestId(TestIds.RefreshIntervalDropdown).should('exist'); | ||
| cy.getByTestId(TestIds.SyncButton).should('exist'); | ||
| cy.getByTestId(TestIds.AvailableAttributes).should('exist'); | ||
| cy.getByTestId(TestIds.SeverityDropdown).should('exist'); | ||
| cy.contains('button', 'Show Resources').should('exist'); | ||
| cy.getByTestId(TestIds.ShowStatsToggle).should('exist'); | ||
| cy.contains('button', 'Export as CSV').should('exist'); | ||
| cy.getByTestId(TestIds.ExecuteVolumeButton).should('exist'); | ||
| cy.getByTestId(TestIds.ExecuteQueryButton).should('exist'); | ||
| cy.getByTestId(TestIds.ShowQueryToggle).should('exist'); | ||
| cy.getByTestId(TestIds.ToogleStreamingButton).should('exist'); | ||
| cy.getByTestId(TestIds.LogsTable).should('exist'); | ||
| cy.getByTestId(TestIds.TenantToggle).should('not.exist'); //Specical feature | ||
| cy.getByTestId(TestIds.AttributeFilters).within(() => { | ||
| cy.getByTestId(TestIds.AvailableAttributes).click(); | ||
| cy.contains('li', 'Content'); | ||
| cy.contains('li', 'Namespaces').should('not.exist'); //Specical feature | ||
| cy.contains('li', 'Pod'); | ||
| cy.contains('li', 'Containers'); | ||
| }) | ||
| if (String(Cypress.env('CLUSTERLOGGING_DATAMODE')) == "select" ) { | ||
| cy.getByTestId(TestIds.SchemaToggle).should('exist'); | ||
| } | ||
| }); | ||
|
|
||
| it('user can display applicatioins logs',{tags:['@smoke','@aggr']}, () => { | ||
| //load Aggregated Logs for the first pod in APP_NAMESPACE1 | ||
| cy.get('[data-test-id="namespace-bar-dropdown"]') | ||
| .find('button[aria-expanded="false"]') | ||
| .click(); | ||
| cy.get('[data-test="namespace-dropdown-menu"]') | ||
| .within(() => { | ||
| cy.contains('button', `${APP_NAMESPACE1}`).click(); | ||
| }); | ||
| cy.get('a[data-test="resource-inventory-item"]') | ||
| .filter(`[href="/k8s/ns/${APP_NAMESPACE1}/pods"]`) | ||
| .click(); | ||
|
|
||
| cy.get('section.pf-v6-c-page__main-section') | ||
| .contains('h1','Pods'); | ||
| cy.get('section[id="content-scrollable"]') | ||
| .within(() => { | ||
| cy.get('tr[data-test-rows="resource-row"]') | ||
| .first() | ||
| .find('td') | ||
| .first() | ||
| .find('a.co-resource-item__resource-name') | ||
| .click(); | ||
| }); | ||
| cy.get('a[data-test-id="horizontal-link-Aggregated Logs"]').click(); | ||
| cy.getByTestId(TestIds.LogsTable,{ timeout: 20000 }).should('be.visible'); | ||
| cy.assertLogInLogsTable(); | ||
| }); | ||
| commonTests(); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
repeated steps like this we can make them reusable in a "utils.ts" file as a "Page Object" concept where you can pass namespace as parameter and do not hardcode it