Define these globally:
ExtentLoggerReporter logger = new ExtentLoggerReporter("/ebs/test/build/"); //The path given here will be used to store temp files for extent,create once.
static ExtentReports extent;
Define this method to initialise Extent configs before Test:
@BeforeTest
public void initialiseExtentReport() {
logger.config().setAutoCreateRelativePathMedia(true);
extent = new ExtentReports();
ExtentHtmlReporter html = new ExtentHtmlReporter("Extent.html");
extent.attachReporter(logger);
extent.attachReporter(html);
extent.loadConfig(new File(System.getProperty("user.dir")+"/extent-config.xml")); //extent-config.xml file content given below
}
For pom.xml add:
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>4.0.9</version>
</dependency>
On Our code, Wherever we are passing/failing the test step, we can use below code to report to extent.html file & flush after every @Test:
extent.createTest("Test case name for our ref","Description of test case which is optional").pass("Test name for report purpose"+" Test passed(You can set any words as per your req)");
OR
extent.createTest("Test case name for our ref","Description of test case which is optional").fail("Test name for report purpose"+" Test failed(You can set any words as per your req)");
Use below snippet once anywhere to flush extent report file(on every test completion this updates report):
@AfterTest
public static void endTest(){
extent.flush();
}
Copy this "extent-config.xml" to project directory directly:
<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
<configuration>
<!-- report theme -->
<!-- standard, dark -->
<theme>standard</theme>
<!-- document encoding -->
<!-- defaults to UTF-8 -->
<encoding>UTF-8</encoding>
<!-- protocol for script and stylesheets -->
<!-- defaults to https -->
<protocol>https</protocol>
<!-- title of the document -->
<documentTitle>ExtentReports 2.0</documentTitle>
<!-- report name - displayed at top-nav -->
<reportName></reportName>
<!-- report headline - displayed at top-nav, after reportHeadline -->
<reportHeadline>Automation Report</reportHeadline>
<!-- global date format override -->
<!-- defaults to yyyy-MM-dd -->
<dateFormat>yyyy-MM-dd</dateFormat>
<!-- global time format override -->
<!-- defaults to HH:mm:ss -->
<timeFormat>HH:mm:ss</timeFormat>
<!-- custom javascript -->
<scripts>
<![CDATA[
$(document).ready(function() {
});
]]>
</scripts>
<!-- custom styles -->
<styles>
<![CDATA[
]]>
</styles>
</configuration>
</extentreports>
Note:
Also on Jenkins job, we can pick this report to send through email after execution to the team.
ExtentLoggerReporter logger = new ExtentLoggerReporter("/ebs/test/build/"); //The path given here will be used to store temp files for extent,create once.
static ExtentReports extent;
Define this method to initialise Extent configs before Test:
@BeforeTest
public void initialiseExtentReport() {
logger.config().setAutoCreateRelativePathMedia(true);
extent = new ExtentReports();
ExtentHtmlReporter html = new ExtentHtmlReporter("Extent.html");
extent.attachReporter(logger);
extent.attachReporter(html);
extent.loadConfig(new File(System.getProperty("user.dir")+"/extent-config.xml")); //extent-config.xml file content given below
}
For pom.xml add:
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>4.0.9</version>
</dependency>
On Our code, Wherever we are passing/failing the test step, we can use below code to report to extent.html file & flush after every @Test:
extent.createTest("Test case name for our ref","Description of test case which is optional").pass("Test name for report purpose"+" Test passed(You can set any words as per your req)");
OR
extent.createTest("Test case name for our ref","Description of test case which is optional").fail("Test name for report purpose"+" Test failed(You can set any words as per your req)");
Use below snippet once anywhere to flush extent report file(on every test completion this updates report):
@AfterTest
public static void endTest(){
extent.flush();
}
Copy this "extent-config.xml" to project directory directly:
<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
<configuration>
<!-- report theme -->
<!-- standard, dark -->
<theme>standard</theme>
<!-- document encoding -->
<!-- defaults to UTF-8 -->
<encoding>UTF-8</encoding>
<!-- protocol for script and stylesheets -->
<!-- defaults to https -->
<protocol>https</protocol>
<!-- title of the document -->
<documentTitle>ExtentReports 2.0</documentTitle>
<!-- report name - displayed at top-nav -->
<reportName></reportName>
<!-- report headline - displayed at top-nav, after reportHeadline -->
<reportHeadline>Automation Report</reportHeadline>
<!-- global date format override -->
<!-- defaults to yyyy-MM-dd -->
<dateFormat>yyyy-MM-dd</dateFormat>
<!-- global time format override -->
<!-- defaults to HH:mm:ss -->
<timeFormat>HH:mm:ss</timeFormat>
<!-- custom javascript -->
<scripts>
<![CDATA[
$(document).ready(function() {
});
]]>
</scripts>
<!-- custom styles -->
<styles>
<![CDATA[
]]>
</styles>
</configuration>
</extentreports>
Note:
Also on Jenkins job, we can pick this report to send through email after execution to the team.
Comments
Post a Comment