Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 119 additions & 1 deletion web/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,131 @@
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']
},
numTestsKeptInMemory: 2,
video: false,
Expand Down
8 changes: 8 additions & 0 deletions web/cypress/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#The following file are copyed from https://github.com/openshift/monitoring-plugin/tree/main/web. This will be synced manually.
web/cypress/support/commands/auth-commands.ts
web/cypress/support/commands/selector-commands.ts
web/cypress/support/commands/utility-commands.ts
web/cypress/views/nav.ts
web/cypress/views/tour.ts
web/cypress/views/utils.ts
web/src/components/data-test.ts
81 changes: 81 additions & 0 deletions web/cypress/e2e/logging/adminConsoleAggregatedLogs.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { TestIds } from '../../../src/test-ids';
import { aggrLogTest, observeLogTest, commonTest } from './testUtils.cy.ts';
import { APP_NAMESPACE1,APP_NAMESPACE2,APP_MESSAGE } from './testUtils.cy.ts';

describe('AdminConsole: Admin in AggregatedLogs', { tags: ['@admin'] }, () => {
before( function() {
cy.uiLoginAsClusterAdmin("first_user");
});

beforeEach( function() {
cy.showAdminConsolePodAggrLog(APP_NAMESPACE1);
});

after( function() {
cy.uiLogoutClusterAdmin("first_user");
});

aggrLogTest();
commonTest();
it('admin can display infra container logs',{tags:['@aggr']}, () => {
cy.showAdminConsolePodAggrLog('openshift-monitoring','alertmanager-main-0');
const indexFields : IndexField = [
{ name: '_timestamp', value: "" },
{ name: 'k8s_container_name', value: "" },
{ name: 'k8s_namespace_name', value: "openshift-monitoring" },
{ name: 'k8s_node_name', value: "" },
{ name: 'k8s_pod_name', value: "alertmanager-main-0" },
{ name: 'openshift_log_type', value: "infrastructure" },
{ name: 'log_source', value: "container" },
{ name: 'hostname', value: "" },
{ name: 'openshift_cluster_id', value: "" },
{ name: 'openshift_sequence', value: "" },
];
cy.assertFieldsInLogDetail(indexFields)
});
})

describe('AdminConsole: Impersonate User in AggregatedLogs',{ tags: ['@admin'] }, () => {
before( function() {
cy.grantLogViewRoles("second_user", `${APP_NAMESPACE1}`);
cy.grantLogViewRoles("second_user", `${APP_NAMESPACE2}`);
cy.cliLogin("second_user")
cy.uiLoginAsClusterAdmin("first_user");
cy.uiImpersonateUser("second_user");
cy.switchToAdmConsole();
});

beforeEach( function() {
cy.showAdminConsolePodAggrLog(APP_NAMESPACE1);
});

after( function() {
cy.uiLogoutUser("second_user");
cy.removeLogViewRoles("second_user", `${APP_NAMESPACE1}`);
cy.removeLogViewRoles("second_user", `${APP_NAMESPACE2}`);
});

aggrLogTest();
commonTest();
})

describe('AdminConsole: User in Aggregated Logs', { tags: ['@user'] }, () => {
before( function() {
cy.grantLogViewRoles("second_user", `${APP_NAMESPACE1}`);
cy.grantLogViewRoles("second_user", `${APP_NAMESPACE2}`);
cy.uiLoginUser("second_user");
});

beforeEach( function() {
cy.showAdminConsolePodAggrLog(APP_NAMESPACE1);
});

after( function() {
cy.uiLogoutUser("second_user");
cy.removeLogViewRoles("second_user", `${APP_NAMESPACE1}`);
cy.removeLogViewRoles("second_user", `${APP_NAMESPACE2}`);
});

aggrLogTest();
commonTest();
})
Loading