I had an example of code in github that create jira ticket when automation test case failed. It collect the ITestResult information and used that to create ticket.
I can use @After on each test scenario but that is too many repetitive code. I want to execute once in the final test execution - something in the hooks or listener.
Questions: Is there any similar mechanism in cucumber to simulate ITestResult? Is it possible to use QAF library?
@Override
public void onTestFailure(ITestResult result) {
JiraPolicy jiraPolicy = result.getMethod().getConstructorOrMethod().getMethod().getAnnotation(JiraPolicy.class);
boolean isTicketReady = jiraPolicy.logTicketReady();
if (isTicketReady) {
// raise jira ticket:
System.out.println("is ticket ready for JIRA: " + isTicketReady);
JiraServiceProvider jiraSp = new JiraServiceProvider("https://naveenautomationlabs.atlassian.net",
"naveenanimation20@gmail.com", "jaizMlfaUkTfffNOVPq29B29", "TA");
String issueSummary = result.getMethod().getConstructorOrMethod().getMethod().getName()
+ "got failed due to some assertion or exception";
String issueDescription = result.getThrowable().getMessage() + "\n";
issueDescription.concat(ExceptionUtils.getFullStackTrace(result.getThrowable()));
jiraSp.createJiraTicket("Bug", issueSummary, issueDescription, "Naveen");
}
}
Please help me. Thanks.