# 4.2 Sample Extent Reports

Extent Reports is a multi-format reporting library for Java Developers which creates an interactive HTML report, an email report, and also provides real-time log information. The ExtentAPI also integrates with the ExtentX server to provide in-depth views of your tests.Extent addresses the reporting issues in TestNG.

Below is the code which can be used to run tests

```
package code;

import java.io.File;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import com.relevantcodes.extentreports.DisplayOrder;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.NetworkMode;

import CONSTANTS;

public class ExtentManager {
    public static ExtentReports extent;
    protected static final String filePath=System.getProperty("user.dir")+File.separator
    +"ExtentReports"+File.separator+"TestReport.html";
    private static boolean replaceExisting=true;
    protected static final DisplayOrder displayOrder= DisplayOrder.NEWEST_FIRST;

    public static ExtentReports getInstance(String EnvironmentToRunOn) {
        if (extent == null) {
            extent = new ExtentReports(filePath, replaceExisting,displayOrder, NetworkMode.OFFLINE); 
            extent.loadConfig(new File(CONSTANTS.ExtentConfigPath));
            Map<String, String> sysInfo = new HashMap<String, String>();
            sysInfo.put("Selenium Version", "2.53.1");
            sysInfo.put("Environment", EnvironmentToRunOn);
            extent.addSystemInfo(sysInfo);            
        }
        return extent;
    }
}

class ExtentReports {

    public ExtentReports extent;
    public ExtentTest test;
    public String getCurrentlyLoggedInUser=System.getProperty("user.name");

    @Test       
   public void InitializeExtentReport(){
        //Instantiating the ExtentReports
        extent=ExtentManager.getInstance(Environment);
        extent.assignProject("Test Extent");
        // start x requires MongoDB hence commented to generate reports on the other machines
        Logger mongoLogger = Logger.getLogger( "org.mongodb.driver" );
        mongoLogger.setLevel(Level.SEVERE);
        extent.x("localhost");*/
        test=extent.startTest("Test1", ""Application started." );
        test.assignAuthor(getCurrentlyLoggedInUser);
        test.assignCategory("RegressionTestCases");
        }
    }
```

We need to keep in mind that the extent reports must be under @Test annotation of TestNG otherwise it will not generate the reports.

After running the tests we will be able to view report in the specified folder as "TestReport.html"

![](https://nsaikiran.gitbooks.io/selenium-2-web-driver-basics/content/assets/ExtentReportsSample.png)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://n-saikiran.gitbook.io/selenium-2-webdriver-advanced/extentreports/42-sample-extent-reports.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
