Skip to content

Commit

Permalink
adressed comments in PR
Browse files Browse the repository at this point in the history
reworked config files to be clearer
fixed typo in reporterOptions
added generate:pdf script to package.json
moved folder creation
  • Loading branch information
roicarrera committed Nov 11, 2024
1 parent 920717b commit cf20766
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 97 deletions.
10 changes: 5 additions & 5 deletions e2e-cypress/Jenkinsfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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
Expand Down
37 changes: 10 additions & 27 deletions e2e-cypress/files/cypress-acceptance.config.ts
Original file line number Diff line number Diff line change
@@ -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
// },
})
});
37 changes: 10 additions & 27 deletions e2e-cypress/files/cypress-installation.config.ts
Original file line number Diff line number Diff line change
@@ -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
// },
})
});
39 changes: 11 additions & 28 deletions e2e-cypress/files/cypress-integration.config.ts
Original file line number Diff line number Diff line change
@@ -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
// },
})
});
2 changes: 1 addition & 1 deletion e2e-cypress/files/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion e2e-cypress/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 8 additions & 5 deletions e2e-cypress/files/pdf-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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' });

Expand All @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion e2e-cypress/files/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion e2e-cypress/files/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }, {
Expand Down
2 changes: 1 addition & 1 deletion e2e-cypress/files/support/test-evidence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
};

0 comments on commit cf20766

Please sign in to comment.