I have been trying to connect my cypress tests with the Zephyr Scale Jira plugin, but I cannot really do it. Can somebody recommend me anything that can be used to connect the cypress tests with zephyr scale?
When running this command: npx cypress run --reporter cypress-zephyr-scale-reporter
, I got this error:
Test Cycle Key: SIITM-R23
Cannot read properties of undefined (reading 'forEach')
TypeError: Cannot read properties of undefined (reading 'forEach')
at new zephyrScaleReporter (C:\Users\MyName\Documents\logoipsum-tests\node_modules\cypress-zephyr-scale-reporter\src\index.js:9:9)
at T.setRunnables (<embedded>:5179:15381)
at Object.onTestsReceivedAndMaybeRecord (<embedded>:5226:425241)
at p.<anonymous> (<embedded>:5226:66734)
at p.emit (node:events:527:28)
at p.emitUntyped (<embedded>:4937:84346)
at <embedded>:4937:91863
at process.processTicksAndRejections (node:internal/process/task_queues:78:11)
The index.js file of the cypress-zephyr-scale-reporter looks like this:
const execSync = require('child_process')
require('dotenv').config();
module.exports = function zephyrScaleReporter(spec, results) {
const tests = results.tests;
const cycleKey = process.env.CYPRESS_ZEPHYR_TEST_CYCLE_KEY;
console.log(`Test Cycle Key: ${cycleKey}`);
tests.forEach((test) => {
// Get the last entry in the title array, which is the actual title of the test
const title = test.title.slice(-1)[0].replace("'", "");
// Get the final result of the test
const resultStates = {
passed: "Pass",
failed: "Fail",
skipped: "Not Executed",
};
const result = resultStates[test.state];
const comment = `Test ran by Cypress Automation.<br>Covered by Cypress Test: <b>${title}</b>`;
// Extract the Case Ids from the test title
let testCaseIdRegExp = new RegExp(
`\\b${process.env.CYPRESS_ZEPHYR_PROJECT_KEY}\\-(\\d|\\w)\+\\b`
);
const testCaseIds = title.match(testCaseIdRegExp);
if (testCaseIds) {
testCaseIds.forEach((caseId) => {
if (caseId.includes(process.env.CYPRESS_ZEPHYR_PROJECT_KEY)) {
const curlOutput = `curl -X POST -d '{"comment": "${comment}", \
"projectKey": "${process.env.CYPRESS_ZEPHYR_PROJECT_KEY}", \
"testCaseKey": "${caseId}", \
"testCycleKey": "${cycleKey}", \
"statusName": "${result}"}' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${process.env.CYPRESS_ZEPHYR_SCALE_KEY}" \
"https://api.zephyrscale.smartbear.com/v2/testexecutions"`;
console.log(curlOutput);
console.log(
`Reporting result of case ${caseId} into cycle ${cycleKey}`
);
execSync(`curl -X POST -d '{"comment": "${comment}", \
"projectKey": "${process.env.CYPRESS_ZEPHYR_PROJECT_KEY}", \
"testCaseKey": "${caseId}", \
"testCycleKey": "${cycleKey}", \
"statusName": "${result}"}' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${process.env.CYPRESS_ZEPHYR_SCALE_KEY}" \
"https://api.zephyrscale.smartbear.com/v2/testexecutions"`);
}
});
}
});
}
My cypress.config.js file looks like this:
const { defineConfig } = require('cypress');
const zephyrScaleReporter = require('cypress-zephyr-scale-reporter');
module.exports = defineConfig({
reporter: 'cypress-zephyr-scale-reporter',
reporterOptions: {
zephyrBaseUrl: 'https://my.url/',
zephyrAccessKey: 'my-access-key',
zephyrSecretKey: 'my-secret-key',
zephyrProjectKey: 'SIITM',
zephyrVersionKey: '1.0',
cyclePrefix: 'CY-',
},
viewportWidth: 1980,
viewportHeight: 1080,
e2e: {
setupNodeEvents(on, config) {
on('after:run', (results) => {
return zephyrScaleReporter(config.zephyrScaleOptions)(results);
});
},
},
});
I created a .env file to define all of the process.env. files, but did not do anything at all.*