Anuj Shrivastav
Anuj Shrivastav

Reputation: 393

Extent Report no generating html

Hi I am trying to create report through Extent Report; the code gives no error and runs successfully but there is no html report generated. Can anyone please help below is my code -

package ca.automation.com;

import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import org.testng.annotations.BeforeTest;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterClass;

public class ExtentReport {

    WebDriver driver;
    ExtentReports extent;
    ExtentTest test;

    @BeforeTest
    public void startReport(){
        extent = new ExtentReports("C:\\Report.html", true);
    }

    @Test
    public void installapp() {
        test = extent.startTest("installapp");
        System.setProperty("webdriver.ie.driver", "C:\\Anuj\\Downloads\\IEDriverServer_Win32_2.46.0\\IEDriverServer.exe");
        driver = new InternetExplorerDriver();
        driver.manage().window().maximize();
        driver.get("https://www.tripadvisor.com/");
        String Title = driver.getTitle();
        Assert.assertTrue(Title.contains("Trip"));
        extent.endTest(test);
    }
}

Upvotes: 4

Views: 32988

Answers (12)

Arthi J
Arthi J

Reputation: 1

Adding bson-xxx.jar solved my same issue. Can try it out.

Upvotes: -2

Vikas Piprade
Vikas Piprade

Reputation: 352

In your test, you are not logging anything in report. If nothing is logged, no report would generate. As given below, try logging something in report. Also as per status of assertion, you can log PASS/FAIL in extentreport

test.log(LogStatus.INFO, "Test Started");
test.log(LogStatus.ERROR, "Test FAILED");

Upvotes: 0

Subodh Singh
Subodh Singh

Reputation: 11

I got this error in testng project even though extent.flush() was added in code. The reason for not generating error was during execution exent.flush() line was not executed due to one of failed assertion. After removing that assertion script was working fine and file got generated as usual.

Upvotes: 1

sheela
sheela

Reputation: 11

Please check if all the configurations are executed.i.e. your @BeforeClass,@AfterClass etc... Sometimes they are skipped and so the extent.html is not generated.

So add the following tag "alwaysRun=true" with the testng annotation e.g.@AfterMethod(alwaysRun = true)

It works :)

Upvotes: 1

arunkumar sambu
arunkumar sambu

Reputation: 663

If it is not working even after adding extent.flush(), Try by adding below dependencies in pom.xml

<dependency>
    <groupId>org.jsoup</groupId>
    <artifactId>jsoup</artifactId>
    <version>1.8.3</version>
</dependency>
<dependency>
    <groupId>org.xerial</groupId>
    <artifactId>sqlite-jdbc</artifactId>
    <version>3.8.11.1</version>
</dependency>
<dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker</artifactId>
    <version>2.3.23</version>
</dependency>
<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver</artifactId>
    <version>3.0.4</version>
</dependency>

Upvotes: 0

Jain Devassy
Jain Devassy

Reputation: 41

I had the same problem in generating Extent reports. The following solution worked for me. Please add these commands at the end: extent.EndTest(test); extent.Flush();

Make sure you add this version from NuGet Packages - ExtentReports 2.41.0

Upvotes: 0

Java_deep
Java_deep

Reputation: 74

Add extent.flush() at the end.

Upvotes: 1

Midhun Kumar
Midhun Kumar

Reputation: 9

Please try this:

import org.testng.annotations.Test;

import com.dell.patientregister.mobilewallet.test.PatientRegister_SmokeTest;
import com.relevantcodes.extentreports.ExtentReports;
import org.testng.annotations.BeforeTest;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class ExtentReport {

WebDriver driver;
ExtentReports extent;
@Test
public void installapp() {

ExtentReports extent = ExtentReports.get(ExtentReport.class);
extent.init("myreport.html", true);
test =  extent.startTest(" Install App");
System.setProperty("webdriver.ie.driver","C:\\Anuj\\Downloads\\IEDriverServer_Win32_2.46.0\\IEDriverServer.exe");
     driver = new InternetExplorerDriver();
     driver.manage().window().maximize();
     driver.get("https://www.tripadvisor.com/");
     String Title = driver.getTitle();
     Assert.assertTrue(Title.contains("Trip"));
     test.Log(LogStatus.Pass, "Login Successful");
     extent.endTest(test);
     extent.flush();
     extent.close();
}
}

Upvotes: 1

ADHITHYA SRINIVASAN
ADHITHYA SRINIVASAN

Reputation: 105

Append extent.flush(); at the end of the test method to write all the test logs to the report file.

Upvotes: 4

manishgdev
manishgdev

Reputation: 148

the flush() and the close() needs to be called for the extent object to write the changes to the file. Call to close() must be done just before end of the Test as it closes the output stream


Call flush() in @AfterMethod method and close() in @AfterSuite method

@AfterMethod
public void afterMethod() {
    extent.flush();
}

@AfterSuite
public void afterSuiteMethod() {
    extent.close();
}

References :- ExtentReports Examples for Java

Upvotes: 2

rajan
rajan

Reputation: 77

Here you go, just copy paste the working code in your project.

import org.testng.annotations.Test;

import com.dell.patientregister.mobilewallet.test.PatientRegister_SmokeTest;
import com.relevantcodes.extentreports.ExtentReports;
import org.testng.annotations.BeforeTest;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class ExtentReport {

    WebDriver driver;
    ExtentReports extent;

    @Test
    public void installapp() {

ExtentReports extent = ExtentReports.get(ExtentReport.class);

        extent.init("myreport.html", true);
         extent.startTest(" Install App");

         System.setProperty("webdriver.ie.driver", "C:\\Anuj\\Downloads\\IEDriverServer_Win32_2.46.0\\IEDriverServer.exe");
         driver = new InternetExplorerDriver();
         driver.manage().window().maximize();
         driver.get("https://www.tripadvisor.com/");
         String Title = driver.getTitle();
         Assert.assertTrue(Title.contains("Trip"));
         extent.endTest();
    }
}

Upvotes: 1

juherr
juherr

Reputation: 5740

Check the documentation: http://extentreports.relevantcodes.com/java/#start-end-tests`

I think extent.flush(); is missing at the end.

Upvotes: 3

Related Questions