I am using cypress.io as automation tool I need to send email notification when my cypress test failed. Is there any way to do it?
I am using cypress.io as automation tool I need to send email notification when my cypress test failed. Is there any way to do it?
You can always link it to another tool via command line. Basically, you pipe the exit code (-1) to an if statement and then run a mail command
An example is in this SO: https://serverfault.com/questions/252448/bash-script-alert-on-error
cypress run
if [ $? -ne 0 ]
then
mailx -s "FAIL" your@email.com
Instead, you should use Module API. You can run cypress from a javascript file and get the results of running cypress.
Check here. https://github.com/cypress-io/cypress/issues/7441#issuecomment-632535986
Below is an example javascript.
// e2e-run-tests.js
const cypress = require('cypress')
cypress.run({ headless: true, browser: 'chrome' })
.then(result => {
const testResults = JSON.stringify(result, null, 2);
// Module API uses "if (result.failures)", that didn't worked for me. That's why I check with "totalFailed > 0"
if (result.totalFailed > 0) {
console.log('Failure(s) in tests! Will send an e-mail')
sendEmail(testResults);
}
process.exit(0);
})
.catch(err => {
console.log('Cypress didn't worked due to some error')
process.exit(0);
});
Also, note that inside the sendEmail method you should call process.exit(0); after the email is sent.