diff --git a/e2e-cypress/Jenkinsfile.template b/e2e-cypress/Jenkinsfile.template index 85762bb7..e5f2a521 100644 --- a/e2e-cypress/Jenkinsfile.template +++ b/e2e-cypress/Jenkinsfile.template @@ -85,7 +85,7 @@ def stageTest(def context) { // "OTP_SECRET=${authenticatorOTPSecret}", "COMMIT_INFO_SHA=${context.gitCommit}", "BUILD_NUMBER=${context.buildNumber}", - "CYPRESS_BASE_URL=${baseUrl}", + "BASE_URL=${baseUrl}", ]) { sh 'npm install' def status = sh(script: 'npm run e2e', returnStatus: true) @@ -95,7 +95,7 @@ def stageTest(def context) { stash(name: "integration-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/integration-junit.xml', allowEmpty: true) stash(name: "acceptance-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/acceptance-junit.xml', allowEmpty: true) - sh 'npx ts-node ./pdf-generator.ts' + sh 'npm run generate:pdf' zip zipFile: 'cypress/pdf.zip', archive: false, dir: 'build/test-results/mochawesome/pdf' archiveArtifacts artifacts: 'cypress/pdf.zip', fingerprint: true, daysToKeep: 2, numToKeep: 3 @@ -106,9 +106,9 @@ def stageTest(def context) { } if (fileExists('build/test-results/screenshots')) { - zip zipFile: 'screenshots.zip', archive: false, dir: 'build/test-results/screenshots' - stash(name: "acceptance-test-screenshots-${context.componentId}-${context.buildNumber}", includes: 'screenshots.zip', allowEmpty: true) - archiveArtifacts artifacts: 'screenshots.zip', fingerprint: true, daysToKeep: 2, numToKeep: 3 + zip zipFile: 'cypress/screenshots.zip', archive: false, dir: 'build/test-results/screenshots' + stash(name: "acceptance-test-screenshots-${context.componentId}-${context.buildNumber}", includes: 'cypress/screenshots.zip', allowEmpty: true) + archiveArtifacts artifacts: 'cypress/screenshots.zip', fingerprint: true, daysToKeep: 2, numToKeep: 3 } return status diff --git a/e2e-cypress/files/cypress-acceptance.config.ts b/e2e-cypress/files/cypress-acceptance.config.ts index 52381440..bdf1616e 100644 --- a/e2e-cypress/files/cypress-acceptance.config.ts +++ b/e2e-cypress/files/cypress-acceptance.config.ts @@ -1,38 +1,21 @@ -import { defineConfig } from 'cypress' -import setupNodeEvents from './plugins/index.js' +import { defineConfig } from 'cypress'; +import baseConfig from './cypress.config'; + export default defineConfig({ - //projectId: '[Your project ID from Cypress cloud]', - reporter: 'cypress-multi-reporters', + ...baseConfig, reporterOptions: { - reporterEnabled: 'mochawesome,./reporters/custom-reporter.js', + ...baseConfig.reporterOptions, mochawesomeReporterOptions: { - reportDir: 'build/test-results/mochawesome', + ...baseConfig.reporterOptions.mochawesomeReporterOptions, reportFilename: 'acceptance-mochawesome', - charts: true, - html: true, - timestamp: true, - json: true }, reportersCustomReporterJsReporterOptions: { + ...baseConfig.reporterOptions.reportersCustomReporterJsReporterOptions, mochaFile: 'build/test-results/acceptance-junit-[hash].xml', - toConsole: true, }, }, e2e: { - baseUrl: process.env.CYPRESS_BASE_URL, - fixturesFolder: "fixtures", - specPattern: 'tests/acceptance/*.cy.ts', - supportFile: "support/e2e.ts", - screenshotsFolder: 'build/test-results/screenshots', - viewportWidth: 1280, - viewportHeight: 720, - experimentalModifyObstructiveThirdPartyCode:true, - video: true, - async setupNodeEvents(on, config) { - return (await import('./plugins/index')).default(on, config); - }, + ...baseConfig.e2e, + specPattern: 'tests/acceptance/**/*.cy.ts', }, - // env: { - // otp_secret: process.env.OTP_SECRET - // }, -}) +}); diff --git a/e2e-cypress/files/cypress-installation.config.ts b/e2e-cypress/files/cypress-installation.config.ts index 29d7f20b..968d7cd0 100644 --- a/e2e-cypress/files/cypress-installation.config.ts +++ b/e2e-cypress/files/cypress-installation.config.ts @@ -1,38 +1,21 @@ -import { defineConfig } from 'cypress' -import setupNodeEvents from './plugins/index.js' +import { defineConfig } from 'cypress'; +import baseConfig from './cypress.config'; + export default defineConfig({ - //projectId: '[Your project ID from Cypress cloud]', - reporter: 'cypress-multi-reporters', + ...baseConfig, reporterOptions: { - reporterEnabled: 'mochawesome,./reporters/custom-reporter.js', + ...baseConfig.reporterOptions, mochawesomeReporterOptions: { - reportDir: 'build/test-results/mochawesome', + ...baseConfig.reporterOptions.mochawesomeReporterOptions, reportFilename: 'installation-mochawesome', - charts: true, - html: true, - timestamp: true, - json: true }, reportersCustomReporterJsReporterOptions: { + ...baseConfig.reporterOptions.reportersCustomReporterJsReporterOptions, mochaFile: 'build/test-results/installation-junit-[hash].xml', - toConsole: true, }, }, e2e: { - baseUrl: process.env.CYPRESS_BASE_URL, - fixturesFolder: "fixtures", - specPattern: 'tests/installation/*.cy.ts', - supportFile: "support/e2e.ts", - screenshotsFolder: 'build/test-results/screenshots', - viewportWidth: 1280, - viewportHeight: 720, - experimentalModifyObstructiveThirdPartyCode:true, - video: true, - async setupNodeEvents(on, config) { - return (await import('./plugins/index')).default(on, config); - }, + ...baseConfig.e2e, + specPattern: 'tests/installation/**/*.cy.ts', }, - // env: { - // otp_secret: process.env.OTP_SECRET - // }, -}) +}); diff --git a/e2e-cypress/files/cypress-integration.config.ts b/e2e-cypress/files/cypress-integration.config.ts index 28c5c1c3..8f3b99b9 100644 --- a/e2e-cypress/files/cypress-integration.config.ts +++ b/e2e-cypress/files/cypress-integration.config.ts @@ -1,38 +1,21 @@ -import { defineConfig } from 'cypress' -import setupNodeEvents from './plugins/index.js' +import { defineConfig } from 'cypress'; +import baseConfig from './cypress.config'; + export default defineConfig({ - //projectId: '[Your project ID from Cypress cloud]', - reporter: 'cypress-multi-reporters', + ...baseConfig, reporterOptions: { - reporterEnabled: 'mochawesome,./reporters/custom-reporter.js', - cypressMochawesomeReporterReporterOptions: { - reportDir: 'build/test-results/mochawesome', + ...baseConfig.reporterOptions, + mochawesomeReporterOptions: { + ...baseConfig.reporterOptions.mochawesomeReporterOptions, reportFilename: 'integration-mochawesome', - charts: true, - html: true, - timestamp: true, - json: true }, reportersCustomReporterJsReporterOptions: { + ...baseConfig.reporterOptions.reportersCustomReporterJsReporterOptions, mochaFile: 'build/test-results/integration-junit-[hash].xml', - toConsole: true, }, }, e2e: { - baseUrl: process.env.CYPRESS_BASE_URL, - fixturesFolder: "fixtures", - specPattern: 'tests/integration/*.cy.ts', - supportFile: "support/e2e.ts", - screenshotsFolder: 'build/test-results/screenshots', - viewportWidth: 1280, - viewportHeight: 720, - experimentalModifyObstructiveThirdPartyCode:true, - video: true, - async setupNodeEvents(on, config) { - return (await import('./plugins/index')).default(on, config); - }, + ...baseConfig.e2e, + specPattern: 'tests/integration/**/*.cy.ts', }, - // env: { - // otp_secret: process.env.OTP_SECRET - // }, -}) +}); diff --git a/e2e-cypress/files/cypress.config.ts b/e2e-cypress/files/cypress.config.ts index d0d7dfde..e02d663f 100644 --- a/e2e-cypress/files/cypress.config.ts +++ b/e2e-cypress/files/cypress.config.ts @@ -18,7 +18,7 @@ export default defineConfig({ }, }, e2e: { - baseUrl: process.env.CYPRESS_BASE_URL || 'https://www.w3schools.com', + baseUrl: process.env.BASE_URL || 'https://www.w3schools.com', fixturesFolder: "fixtures", specPattern: 'tests/**/*.cy.ts', supportFile: "support/e2e.ts", diff --git a/e2e-cypress/files/package.json b/e2e-cypress/files/package.json index 933240dd..af71b366 100644 --- a/e2e-cypress/files/package.json +++ b/e2e-cypress/files/package.json @@ -15,7 +15,8 @@ "delete-junit-results": "rimraf build/test-results", "e2e": "npm-run-all delete-junit-results cypress:run-installation cypress:run-integration cypress:run-acceptance", "combine:reports": "npm-run-all junit-installation-report junit-integration-report junit-acceptance-report", - "e2e:jenkins:record": "npm run delete-junit-results && npm run cypress:run-installation -- --record && npm run cypress:run-integration -- --record && npm run cypress:run-acceptance -- --record" + "e2e:jenkins:record": "npm run delete-junit-results && npm run cypress:run-installation -- --record && npm run cypress:run-integration -- --record && npm run cypress:run-acceptance -- --record", + "generate:pdf": "ts-node ./pdf-generator.ts" }, "private": true, "devDependencies": { diff --git a/e2e-cypress/files/pdf-generator.ts b/e2e-cypress/files/pdf-generator.ts index 48d8bc20..05c8b317 100644 --- a/e2e-cypress/files/pdf-generator.ts +++ b/e2e-cypress/files/pdf-generator.ts @@ -11,16 +11,16 @@ async function expandReportTestCases(htmlPage: puppeteer.Page) { }); } +const mochawesomeDir = path.resolve(__dirname, 'build/test-results/mochawesome/'); + const isLocal = process.env.NODE_ENV === 'local'; (async () => { try { - const files = await fs.promises.readdir('build/test-results/mochawesome/'); + const files = await fs.promises.readdir(mochawesomeDir); for (const file of files) { - if (!fs.existsSync(path.resolve(__dirname, 'build/test-results/mochawesome/', 'pdf'))) - fs.mkdirSync(path.resolve(__dirname, 'build/test-results/mochawesome/', 'pdf')); if (!file.endsWith('.html')) { continue; } @@ -31,7 +31,7 @@ const isLocal = process.env.NODE_ENV === 'local'; executablePath }); const page = await browser.newPage(); - const htmlFullFilePath = path.resolve(__dirname, 'build/test-results/mochawesome/', file); + const htmlFullFilePath = path.resolve(__dirname, mochawesomeDir, file); await page.goto(`file://${htmlFullFilePath}`, { waitUntil: 'networkidle2' }); @@ -52,8 +52,11 @@ const isLocal = process.env.NODE_ENV === 'local'; ` }); + if (!fs.existsSync(path.resolve(__dirname, mochawesomeDir, 'pdf'))) + fs.mkdirSync(path.resolve(__dirname, mochawesomeDir, 'pdf')); + await page.pdf({ - path: path.resolve(__dirname, 'build/test-results/mochawesome/', 'pdf/', file.replace('.html', '.pdf')), + path: path.resolve(__dirname, mochawesomeDir, 'pdf/', file.replace('.html', '.pdf')), format: 'A4', printBackground: true, }); diff --git a/e2e-cypress/files/support/commands.ts b/e2e-cypress/files/support/commands.ts index 910a01b6..b85f54cd 100644 --- a/e2e-cypress/files/support/commands.ts +++ b/e2e-cypress/files/support/commands.ts @@ -23,6 +23,6 @@ declare global { loginToAADWithMFA(username: string, password: string); sessionLoginWithMFA(username: string, password: string); getTOTP(); - addScreenshot(title: string, screenshot: string); + addContextPath(title: string, screenshot: string); } } diff --git a/e2e-cypress/files/support/e2e.ts b/e2e-cypress/files/support/e2e.ts index 445902d0..714ccedf 100644 --- a/e2e-cypress/files/support/e2e.ts +++ b/e2e-cypress/files/support/e2e.ts @@ -17,7 +17,7 @@ afterEach(function() { consoleLogs.splice(0); }) -Cypress.Commands.add('addScreenshot', (title: string, screenshot: string) => { +Cypress.Commands.add('addContextPath', (title: string, screenshot: string) => { cy.on('test:after:run', (attributes) => { // The context needs the screenshot path relative to the build/test-results/mochawesome folder addContext({ test: attributes }, { diff --git a/e2e-cypress/files/support/test-evidence.ts b/e2e-cypress/files/support/test-evidence.ts index 5b252f20..eca2d219 100644 --- a/e2e-cypress/files/support/test-evidence.ts +++ b/e2e-cypress/files/support/test-evidence.ts @@ -68,7 +68,7 @@ export const takeScreenshotEvidence = (testName: string, testStep: number, testS // Create a relative path from the screenshots folder to the mochawesome test-results folder const relativePath = path.relative('build/test-results/mochawesome', result.path.replace(/^.*(build.*)$/, '$1')); - cy.addScreenshot(`${testName} ${testStep} ${testSubStep}`, relativePath); + cy.addContextPath(`${testName} ${testStep} ${testSubStep}`, relativePath); }); }); };