Reputation: 1488
I run Windows10, I have a project made on Cypress and I want to log the test results both on a file AND on console: I tried just printing on a file, using in my package.json
this script:
"scripts": {
"open": "./node_modules/.bin/cypress open",
"runheadless": "./node_modules/.bin/cypress run --headless --browser chrome
--spec 'cypress/integration/webpages.spec.js' > cypresstest.log"
}
And this runs smoothly; my issue is that there are more than 100 tests and it takes very long time (like 20 minutes); so I can't check if something got frozen or is working fine, because nothing is printed on console.
So I tried with
"runheadless": "./node_modules/.bin/cypress run --headless --browser chrome
--spec 'cypress/integration/webpages.spec.js' | tee cypresstest.log"
But since I'm on windows, it says
tee is not recognized as internal or external program
Is there a way, or a plugin, or something I can do to simply print both on console AND on a file log?
Upvotes: 2
Views: 9012
Reputation: 1427
Cypress-terminal-report has such a feature, or you can use a custom command including cy. task instead of cy.log - for example:
cypress plugin file
module.exports = (on, config) => {
on('task', {
log (message) {
console.log(message)
return null
}
})
}
custom command:
Cypress.Commands.add("logInAndOut", (message) => {
cy.log(message)
cy.task('log', message)
});
test file
cy.logInAndOut('My log')
Edit: I found another solution - Commands. overwrite(), and I`ll list an example, but I do not recommend it, since if other people try to use the code after you - won't know the change:
Cypress.Commands.overwrite('log', (originalFn, message, args...) => {
console.log(message, args...)
// originalFn is the existing `log` command that you need to call
// and it will receive whatever you pass in here.
//
// make sure to add a return here!
return originalFn(message, args...)
})
Upvotes: 1