I’m trying to create a folder to save the screenshots I capture from Cypress in a custom folder inside screenshots, but it’s not working. The problem is that when the code is executed, at the end it changes the route that I put and leaves the one that is by default.
The code is:
folderName = 'ROX';
var datetime = new Date();
datetime = datetime.toISOString().slice(0, 19).replace('T', '_');
datetime = datetime.replace(/:s*/g, '_');
screenshotsFolder = __dirname + "/cypress/screenshots/" + folderName + '/' + datetime + '/';
console.log("It should be: ", screenshotsFolder);
let results = await cypress.run({
browser: 'chrome',
configFile: __dirname + '/cypress.config.js',
//spec: __dirname + '/cypress/e2e/investigacion/testWeb.cy.js',
reporter: "cypress-multi-reporters",
reporterOptions: {
"reporterEnabled": "mochawesome",
"mochawesomeReporterOptions": {
"reportDir": "cypress/reports/" + folderName + '/' + datetime + "/json/",
//"reportDir": "cypress/reports/json/",
"overwrite": false,
"html": false,
"json": true
}
},
videosFolder: __dirname + '/cypress/videos',
screenshotsFolder: screenshotsFolder,
//screenshotsFolder: __dirname + "/cypress/screenshots/",
});
console.log("But it is this", results.config.screenshotsFolder);
Output:
It should be: C:UsersxeomDesktopAyudantiav2_scriptscript/cypress/screenshots/ROX/2023-05-08_16_13_27/
But it is this C:UsersxeomDesktopAyudantiav2_scriptscriptcypressscreenshots
How can I change it?
2
Answers
screenshotsFolder
should be in theconfig
sectioncode source
You need to use the start function from the Cypress API and also you can use path.join method for defining the folder path.
I have just updated your existing code , You can try with this :-