cypress-zapi-util v2.2.4
cypress-zapi-util
This library help us to create a test cycle after cloning from an existing one. After creating cycle (or use an existing), library can update the test results in Jira-Zephyr
cypress.json
"env": {
"dryRun": false, //true: if you are running test locally and DONT want to update results in Jira-Zephyr
"jiraProjectId": "18881", //project id from Jira
"cycleIdToBeClone": "3553", //cycle to be cloned
"cloneCycle": false, // true: if you want to clone new cycle, false: if you want to update results in an existing cycle
"versionId": "", //Use numeric value i.e 28921 for released and -1 /blank for unreleased
"errorFilePath": "D:\\Work\\Error.txt", //some file for storing error and exceptions
"apiBaseURL": "https://jira.mycompany.com/rest/zapi/latest",
"auth": "ZZyyxx" //basic auth token
"rootFolderScreenShot": "D:\\Work\\Cypress\\Code\\cypress\\screenshots\\", //screenshots root folder
"cycleIdFile": "D:\\Work\\Cypress\\Code\\cypress\\screenshots\\cycle.txt" //file where we store cycle id.
}
In case you want to clone new cycle make sure you change cloneCycle to true and delete existing cycle text file which is configured cycleIdFile
Installation
npm i cypress-zapi-util
Usage
cypress\support
Create base.js
var ZAPI = require('cypress-zapi-util');
var path = require('path');
beforeEach(() => {
})
afterEach(() => {
Cypress.on('uncaught:exception', (err, runnable) => {
throw err
})
if(!Cypress.env('dryRun')) {
const testResult = Cypress.mocha.getRunner().suite.ctx.currentTest.state;
let intTestResult = "0";
let titleString = Cypress.mocha.getRunner().suite.ctx.currentTest.title;
let issueKey = "";
//It('Issue: TMP-727, CycleId: 3581 ~ Should do something5', () => …)
//If you provide CycleId: 3581 then CycleId from Configuration will be overwritten and will be used for updating result
cy.task('getZapiPackagePath').then((packagePath) => {
cy.exec('node "'+packagePath+path.sep+'custom'+path.sep+'helper" getValueByTypeFromString "'+ titleString+'" "Issue"').then((results) => {
let result = results.stdout.replace('--------make-runnable-output--------','').replace('------------------------------------', '').trim();
if(result.includes('undefined') || result.includes('Error')) {
cy.writeFile(Cypress.env('errorFilePath'), result+"\n",{ flag: 'a+' });
}
else {
issueKey = result;
console.log('Utility is updating results for '+issueKey);
switch (testResult) {
case 'passed':
intTestResult = "1";
break;
case 'failed':
intTestResult = "2";
break;
default:
intTestResult = "-1";
}
cy.exec('node "'+packagePath+path.sep+'custom'+path.sep+'helper" getValueByTypeFromString "'+ titleString+'" "CycleId"').then((results) => {
result = results.stdout.replace('--------make-runnable-output--------','').replace('------------------------------------', '').trim();
if(result.includes('undefined') || result.includes('Error')) {
cy.readFile(Cypress.env('cycleIdFile')).then(cycleId => {
if(cycleId != undefined ) {
ZAPI.reportTestResultToZephyr(Cypress.env('apiBaseURL'), cycleId, Cypress.env('jiraProjectId'), issueKey, intTestResult);
} else {
cy.writeFile(Cypress.env('errorFilePath'), issueKey + "\tCycleId is neither defined at Test level nor the cycle id found in file "+Cypress.env('cycleIdFile')+"\n",{ flag: 'a+' });
}
});
}
else {
ZAPI.reportTestResultToZephyr(Cypress.env('apiBaseURL'), result, Cypress.env('jiraProjectId'), issueKey, intTestResult);
}
})
}
})
})
}
})
before(() => {
Cypress.on('uncaught:exception', (err, runnable) => {
throw err
})
cy.writeFile(Cypress.env('errorFilePath'), "Date:: "+Date.now()+"\n");
if(!Cypress.env('dryRun')) {
if(Cypress.env('cloneCycle')) {
cy.task('readFileMaybe', Cypress.env('cycleIdFile')).then((textOrNull) => {
if(textOrNull == null) {
ZAPI.cloneCycleForExecution(Cypress.env('apiBaseURL'), Cypress.env('cycleIdToBeClone'), Cypress.env('jiraProjectId'));
}
})
}
}
})
after(() => {
})
Add base.js to cypress\support\index.js
import './base'
cypress\plugins\index.js
const fs = require('fs')
const path = require('path');
module.exports = (on, config) => {
on('task', {
readFileMaybe (filename) {
if (fs.existsSync(filename)) {
return fs.readFileSync(filename, 'utf8')
}
return null
},
getZapiPackagePath() {
return path.dirname(require.resolve("cypress-zapi-util/package.json"));
}
})
};
Example for taking screenshot and uploading
var ZAPI = require('cypress-zapi-util');
it('Issue: WDX-496 ~ Should do something2', () => {
console.log(Cypress.env('baseUrl'));
cy.screenshot('filename');
ZAPI.attachCustomFiles(Cypress.mocha.getRunner().test.title, "filename");
})
Example for getting duplicate test cases in cycle folders
CycleFoldersScanReportForDuplicateTestCases.txt will be generated under user's Download folder
var ZAPI = require('cypress-zapi-util');
it('Issue: WDX-726, CycleId: 3581 ~ Should do something1', () => {
ZAPI.getDuplicateTestCasesInCycleFolders("2922", "17910", "28921"); //cycleId, projectId, versionId
})
it('Issue: WDX-725 ~ Should do something1', () => {
ZAPI.getDuplicateTestCasesInCycleFolders("2922", "17910", "28921"); //cycleId, projectId, versionId
})
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago