1

I want to store all new and previous reports in my directory.

Current behavior

Right now after running tests by 'npm run test' previous reports are deleted or appended (when i delete line clean reports in package.json).

Desired behavior

I want to give my directory path a dynamic name e.g with current date or number so previous ones stays where they are but i don't know if it is possible to do it inside cypres.json. Is there any solution workaround?

Code

package.json

"scripts": { "clean:reports": rmdir /S /Q cypress\reports && mkdir cypress\reports && mkdircypress\reports\mochareports",

"pretest": "npm run archive-report && npm run clean:reports",

"scripts": "cypress run --browser chrome",

"combine-reports": "mochawesome-merge ./cypress/reports/chrome/mocha/*.json > cypress/reports/chrome/mochareports/report.json",

"generate-report": "marge cypress/reports/chrome/mochareports/report.json -f report -o cypress/reports/chrome/mochareports",

"posttest-chrome": "npm run combine-reports && npm run generate-report",

"test-chrome": "npm run scripts || npm run posttest-chrome"

cypress.json

"reporter": "cypress-multi-reporters",

"reporterOptions": {

"reporterEnabled": "mochawesome",

"mochaFile": "raports/my-test-output-.xml",

"mochawesomeReporterOptions": {

"reportDir": "cypress/reports/mocha",

"quite": true,

"overwrite": false,

"html": false,

"json": true

} }

simillar: ReportDir of a mochawesome reporter option in cypress.json to point to folder created at run time named after timestamp

dawidk09
  • 91
  • 10

1 Answers1

0

A workaround: If you start the tests in some CI, then once npm run test command is finished you can add additional steps to do this for you, for bash it would be something like:

dirName="$(date +"%d-%m-%Y-%H:%M:%S")"
mkdir $dirName
mv cypress/screenshots/*.json $dirName

More details regarding the dirName here.

Zaista
  • 1,272
  • 8
  • 18
  • I would like to make entire process automatic, I hope there is something to do in package.json e.g in posttest – dawidk09 Sep 17 '21 at 11:16
  • Sure thing: just add "posttest": "./posttest.sh" to your package.json, and add these commands in the posttest.sh file next to package.json. You'll probably need to play around with correct paths. – Zaista Sep 17 '21 at 11:29
  • I am getting ./posttest.sh '.' is not recognized as an internal or external command, operable program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! cypress-tests@1.0.0 posttest: `./posttest.sh` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the cypress-tests@1.0.0 posttest script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: – dawidk09 Sep 17 '21 at 12:12
  • If you use windows then please adjust the commands as these ones are linux specific, you can start from here: https://stackoverflow.com/questions/50243229/run-batch-file-in-npm-script – Zaista Sep 17 '21 at 12:56
  • Thanks it works! I have added "save-reports": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./posttest.ps1" to Scripts in package.json and in posttest.ps1 commands like copy-item, rename-item – dawidk09 Sep 22 '21 at 08:02