T.Che
T.Che

Reputation: 345

Why only second test suite print in extent report?

I have generated extent report using multiple test suite.

But it only display last test suite in extent report.

here is my code

@BeforeSuite
    public void beforeSuite() {

        htmlReporter = new ExtentHtmlReporter(Utils.getReportDir() + "/report.html");
        htmlReporter.loadXMLConfig(String.valueOf(new File("src/test/java/extentreports/extent-config.xml")));
        extent = new ExtentReports();
        extent.attachReporter(htmlReporter);

        extent.setSystemInfo("OS Name", System.getProperty("os.name"));
        extent.setSystemInfo("OS Version", System.getProperty("os.version"));
        extent.setSystemInfo("Java Version", System.getProperty("java.version"));
        extent.setSystemInfo("User Name", System.getProperty("user.name"));

        htmlReporter.config().setChartVisibilityOnOpen(true);
        htmlReporter.config().setDocumentTitle("Automation");
        htmlReporter.config().setReportName("Report");
        htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
        htmlReporter.config().setTheme(Theme.DARK);

    }

 @AfterMethod
    public void getResult(ITestResult result) {
        if (result.getStatus() == ITestResult.FAILURE) {
            test.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + " Test case FAILED due to below issues:", ExtentColor.RED));
            test.fail(result.getThrowable());
            String screenShotPath = MobileActions.Screenshot("Failed");

            try {
                test.addScreenCaptureFromPath(screenShotPath);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else if (result.getStatus() == ITestResult.SUCCESS) {
            test.log(Status.PASS, MarkupHelper.createLabel(result.getName() + " Test Case PASSED", ExtentColor.GREEN));
        } else {
            test.log(Status.SKIP, MarkupHelper.createLabel(result.getName() + " Test Case SKIPPED", ExtentColor.ORANGE));
            test.skip(result.getThrowable());
        }
    }



@AfterSuite
    public void flushReport() {
        extent.flush();
        loginAndroid.quitTest();
    }

to generate report i use below code with every test case.

test = extent.createTest("Add Image on Canvas");

and testng.xml as below.

 <suite-files>

        <suite-file path="Font_Module.xml"></suite-file>

        <suite-file path="Image_Module.xml"></suite-file>


    </suite-files>

it only display second suite result in extent report.

suggest me how to add all test suite result in extent report.

Upvotes: 1

Views: 776

Answers (2)

swarup kshatriya
swarup kshatriya

Reputation: 1

    package com.helper;

    import java.io.File;
    import java.io.IOException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;
    import org.testng.annotations.AfterSuite;
    import org.testng.annotations.BeforeGroups;
    import org.testng.annotations.BeforeSuite;

    import com.relevantcodes.extentreports.ExtentReports;
    import com.relevantcodes.extentreports.ExtentTest;

    public class ExtentReportMain {
        public static ExtentReports extent;
        public static ExtentTest logger;
        @BeforeSuite
        public static void reportsetup(){
            
            GenerateReport();
        }
        public static String capture(WebDriver driver) throws IOException {
            File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
            File Dest = new File("src/../BStackImages/" + System.currentTimeMillis()
            + ".png");
            String errflpath = Dest.getAbsolutePath();
            FileUtils.copyFile(scrFile, Dest);
            return errflpath;
        }
        @AfterSuite
        public void wirteExtent(){
            extent.flush();
        }
        
        public static ExtentReports getInstance() {
            if(extent == null) {
                reportsetup();
            }   
            return extent;
        }
        
        public static void GenerateReport(){
            
            if(extent==null){
                DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH-mm-ss"); 
                String destDir = dateFormat.format(new Date());
                extent=new ExtentReports(System.getProperty("user.dir")+"/ExtentReport/ExtentReports_"+destDir+"/Swarupreport.html");
                extent.addSystemInfo("Host Name", "Swarup PC");
                extent.addSystemInfo("Environment ", "Extent Test");
                extent.addSystemInfo("Username","Swarup");
                extent.loadConfig(new File(System.getProperty("user.dir")+"\\extent-config.xml"));
            }
            
        }
    }




        

Upvotes: 0

Sameer Arora
Sameer Arora

Reputation: 4507

Change your @BeforeSuite to @BeforeTest AND
@AfterSuite to @AfterTest and it should work fine.

Upvotes: 1

Related Questions