Reputation: 43
I'm trying to generate a TestNG report from a test case suite run, this test cases are allowed to run up to three times in case of failing on the first or second run. The report I'm able to generate only displays the last run with the result, and what I want to do is to generate a report that displays every run, so if a test case ran 3 times is listed 3 times in the report. This is the code I have so far:
LinkedList<Map<String, ISuiteResult>> componentResults = new LinkedList<Map<String, ISuiteResult>>();
LinkedHashMap<String, String> testNames = new LinkedHashMap<String, String>();
List<String> mustPassTests = getMustPass(testSuite);
Map<String, ISuiteResult> r = testSuite.getResults();
componentResults.add(r);
for(ISuiteResult r2 : r.values()) {
ITestContext testContext = r2.getTestContext();
String testName = testContext.getName();
ITestNGMethod[] methods = testContext.getAllTestMethods();
Calendar startCal = Calendar.getInstance();
startCal.setTime(testContext.getStartDate());
long start = startCal.getTimeInMillis();
Calendar endCal = Calendar.getInstance();
endCal.setTime(testContext.getEndDate());
long end = endCal.getTimeInMillis();
duration += end-start;
for(int i = 0; i < methods.length; i++) {
testNames.put(methods[i].getMethodName(), testName);
}
}
I thought I could use the list of invoked methods, excluding the config ones, but the map does not accepts duplicate keys.
for(IInvokedMethod invoked : invokedMethods){
String invokedName = invoked.getTestMethod().getMethodName();
if(!invokedName.contains("after")){
if(!invokedName.contains("before")){
testNames.put(invoked.getTestMethod().getMethodName(), testName);
}
}
}
Is there any way to use another primary key that allows me to list every single run instead of the test case result?
Upvotes: 2
Views: 1445
Reputation: 5908
You can use selenium testing-framework - QAF formerly ISFW that is based on testng and provides descriptive reporting with the need you have. Here are some of the snapshots.
Upvotes: 2
Reputation: 43
Finally I was able to find a solution to the problem I had by introducing the following changes:
List<IInvokedMethod> invokedMethods = testSuite.getAllInvokedMethods();
LinkedHashMap<String, String> testNames = new LinkedHashMap<String, String>();
Map<String, ISuiteResult> r = testSuite.getResults();
for(ISuiteResult r2 : r.values()) {
ITestContext testContext = r2.getTestContext();
String testName = testContext.getName();
ITestNGMethod[] methods = testContext.getAllTestMethods();
Calendar startCal = Calendar.getInstance();
startCal.setTime(testContext.getStartDate());
long start = startCal.getTimeInMillis();
Calendar endCal = Calendar.getInstance();
endCal.setTime(testContext.getEndDate());
long end = endCal.getTimeInMillis();
duration += end-start;
for(int i = 0; i < methods.length; i++) {
System.out.println(methods[i].getMethodName());
testNames.put(methods[i].getMethodName(), testName);
}
}
for(IInvokedMethod invoked : invokedMethods){
if(!invoked.getTestMethod().toString().contains("after")){
if(!invoked.getTestMethod().toString().contains("before")){
testNames.put(invoked.getTestResult().getName(), invoked.getTestResult().getTestContext().getName());
}
}
}
I'm now using a list of invoked methods, excluding the configuration ones, identified by the after and before annotations
Upvotes: 0