I have configured a Selenium TestNG project in Jenkins which contains 35 Test Cases. I'm not getting any emails when a test case fails in my Test Suite.
How can I configure Jenkins or my test suite need to get email when a test case fails?
I have configured a Selenium TestNG project in Jenkins which contains 35 Test Cases. I'm not getting any emails when a test case fails in my Test Suite.
How can I configure Jenkins or my test suite need to get email when a test case fails?
This is effectively useful if we implement and use in scripts. #ValueAddition. There are multiple reasons why the test fails:
But if the script is failing due to xpath and some valid reason then you have to maintain for re work on your scripts.
Solution -
package TestNGDemo;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
// implement IRetryAnalyzer interface
public class Retry implements IRetryAnalyzer{
// set counter to 0
int minretryCount=0;
// set maxcounter value this will execute our test 3 times
int maxretryCount=2;
// override retry Method
public boolean retry(ITestResult result) {
// this will run until max count completes if test pass within this frame it will come out of for loop
if(minretryCount<=maxretryCount)
{
// print the test name for log purpose
System.out.println("Following test is failing===="+result.getName());
// print the counter value
System.out.println("Retrying the test Count is=== "+ (minretryCount+1));
// increment counter each time by 1
minretryCount++;
return true;
}
return false;
}
}
Hope it helps you !
You can use email-ext Jenkins plugin and create a post build step. With this you can set what the email contains (for example create an html body for the email, attach the results).
If you check the advanced options you can add triggers for what case it should send the email.