Adding extent reports to any project

If we want to add extent reports to our project we have to add dependency to our pom.xml

<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>3.0.0</version>
</dependency>

Then in our project we have to add a file called config.xml at project level Then we add a file ExtentManager anywhere in our project .In our case we added in src/test/resources

Then the test for which we want to generate extent reports we instantiate the ExtentReport and ExtentTest object either at global level in that class file or we can define them in a parent class which this test class is extending

public ExtentReports rep = ExtentManager.getInstance();
public ExtentTest test;

Then we can instantiate the test object in any or every testcase for which we want to generate the extent reports

test = rep.startTest("LoginTest");
test.log(LogStatus.INFO,"Login Test starting");

If a test fails we type this to log a failure

test.log(LogStatus.FAIL , "Test failed");

To log a screenshot in a report we first take a screenshot and then log it in our report.In the below example screenshotFile is the name of screenshot which we took on test failure and which we want to log in our report.

test.log(LogStatus.INFO,"Screenshot-> "+ test.addScreenCapture(System.getProperty("user.dir")+"//screenshots//"+screenshotFile));