0

I have Sanity testsuite testng xml which contains multiple testsuites and I want to get results of Sanity testsuite and display on console.

I tried using IsuiteListener and I am getting results of individual test suites.

Can someone help me in getting consolidated results for all the testsuites running under sanity testsuite?

package utilities;

import java.util.Map;

import org.testng.ISuite;
import org.testng.ISuiteListener;
import org.testng.ISuiteResult;
import org.testng.Reporter;

public class Listener implements ISuiteListener 
{

    @Override
    public void onStart(ISuite arg0) {
        Reporter.log("About to begin executing Suite " + arg0.getName(), true);

    }

    @Override
    public void onFinish(ISuite suite) 
    {
        Map<String,ISuiteResult> results=suite.getResults();
        for(String key: results.keySet())
        {
             ISuiteResult con = results.get(key);

            int totaltestcases=con.getTestContext().getAllTestMethods().length;

        int passtestcases= con.getTestContext().getPassedTests().size();
        int failedtestcases=con.getTestContext().getFailedTests().size();
        int skippedtestcases=con.getTestContext().getSkippedTests().size();
        int percentage=(passtestcases*100)/totaltestcases;
        System.out.println("PASS PERCENTAGE : "+percentage+"%");

        }
    }



}

Below is the Sanity Test Suite xml

<suite name="Sanity Test Suite">
<listeners>

 <listener class-name="utilities.Listener"></listener>

 </listeners>
   <suite-files>
    <suite-file path="TestSuit_01.xml"/>
    <suite-file path="TestSuit_02.xml"/>

</suite-files>
</suite>
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Yashica
  • 45
  • 1
  • 2
  • 6

1 Answers1

0

You should build an implementation of the TestNG listener org.testng.IReporter which gets executed after all the suites have run to completion and then refer to this listener in your suite xml file via the <listeners> tag.

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
  • Hi @Krishnan, I tried with IReporter but now suite.getresults is not returning anything.ISuite suite = suites.get(0); Map results=suite.getResults(); for ( ISuiteResult sr : results.values() ) { ITestContext tc = sr.getTestContext(); System.out.println("Passed tests for suite '" + suite.getName() + "' is:" + tc.getPassedTests().getAllResults().size()); } code is not going into loop – Yashica Jan 08 '18 at 18:27
  • @Yashica - That is a basic use case for `IReporter`. So I would be surprised to hear that it doesnt work. Can you please post your complete code on perhaps github and share the link so that I can take a look at it to see what is going wrong ? – Krishnan Mahadevan Jan 09 '18 at 02:01
  • Since i am using suite.get(0) which is my sanity suite here and it doesnot have any testresults thats why results.value() was coming as null. i resolved by summation of every other testcase result and then displaying the consolidated report. thank you so much for your help !! – Yashica Jan 09 '18 at 15:22