ExtentReport is generated only for the last Test in the suie | Selenium Forum
P
Pravin V. Kumbhare Posted on 13/08/2020

I have created basic project structure (per instructed in video 1 of TestNG Framework section).

Every time I run the testng.xml, all the siz Tests are run (as shown by TestNG tab in console), but the Extent Report shows only the last Test.

Below is my code.

 

Extent Report initialization:

package reportsgen;

import java.io.File;
import java.util.Date;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;

public class InitializeExtRep {
static String exRepPath;
static ExtentReports exRep;
static ExtentSparkReporter exSpa;
static Date d = new Date();
static File f;

public static ExtentReports initializeExtRep() {
exRepPath = System.getProperty("user.dir") + "\\ext-reports\\" + d.toString().replaceAll(":", "-").replaceAll(" IST ", " ").substring(4);
f=new File(exRepPath+"\\Screenshots");
f.mkdirs();
exRep = new ExtentReports();
exSpa = new ExtentSparkReporter(exRepPath);
exSpa.config().setReportName("Kapil Temp Reports");
exRep.attachReporter(exSpa);
return exRep;

}
}

 

Test Base code:

package testbase;

import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;

import reportsgen.InitializeExtRep;

public class TestBase {
ExtentReports exRep;
protected ExtentTest exTest;

@BeforeMethod
public void initExtRep(ITestResult itRes) {
//System.out.println(itRes.getMethod().getMethodName());;
exRep = InitializeExtRep.initializeExtRep();
exTest = exRep.createTest("Kapil Temp Test");

}

@AfterMethod
public void finalizeExtRep() {
exRep.flush();

}

public void infoLogGen(String msg){
exTest.log(Status.INFO, msg);
}

}

 

Suite xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test Suite A">
<test name="Test A">
<classes>
<class name="suitea.TestA" />
<class name="suitea.TestAA" />
</classes>
</test>

</suite>
<!-- Default suite -->

 

Main testng.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test Suite Main">
<suite-files>
<suite-file path="suitea.xml" />
<suite-file path="suiteb.xml" />
<suite-file path="suitec.xml" />
</suite-files>

</suite> <!-- Default suite -->

 


A
Ashish Replied on 14/08/2020

Please zip and send your project


P
Pravin V. Kumbhare Replied on 14/08/2020

I got this fixed.

The issue was, in ExtentManager class, I didn't check the ExtentReport object is null or not. Every time I was creating new object. Now using "if" clause, I'm checking if it is already initialized or not. If it's null, then only I'm creating the object and if it's null, I'm simply returning the same object.

Don't understand completely how this affets, but this is working for me.

What is your thought?

 

Thank you,

Pravin.


A
Ashish Replied on 15/08/2020

Yes this will create an issue

Extent reports object has to be created just once

Then you can add multiple tests in the same report object.

If you are not checking it for null then you are creating a new extent object for every test. So only the last test is reflected.


Related Posts