Extent Report (http://extentreports.com/) is undoubtedly a great Reporting Library for any test automation framework.
Below is one example of how to customize ExtentReport for your project need.
The example will guide you on How to add a Hyperlink into HTML report.
Step 1: Create your own class as below
*Target is specified as _blank so the link will open in new window. You you wants to open in same window then remove target='_blank'
Step 2: Create object of ExtentLink and add it to Extent Log as below
Thats All you need!!
Conclusion:
You can easily customize ExtentReport by adding any HTML object like Links, Label, Tables, Image with the help of "Markup" class.
Below is one example of how to customize ExtentReport for your project need.
The example will guide you on How to add a Hyperlink into HTML report.
Step 1: Create your own class as below
import com.aventstack.extentreports.markuputils.Markup;
/**
* Class that represents Hyperlink
*/
class ExtentLink implements Markup {
private String linkUrl;
public String getLinkUrl() {
return this.linkUrl;
}
public void setLinkUrl(String linkUrl) {
this.linkUrl = linkUrl;
}
public String getLinkText() {
return this.linkText;
}
public void setLinkText(String linkText) {
this.linkText = linkText;
}
private String linkText;
@Override
public String getMarkup() {
return htmlTag;
}
@Override
public String toString() {
return this.linkText;
}
}
Step 2: Create object of ExtentLink and add it to Extent Log as below
ExtentReports extent = new ExtentReports();
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("extent.html");
extent.attachReporter(htmlReporter);
//start of test case
ExtentTest test = extent.createTest("TestName");
//....
//Add a link in test report
final ExtentLink link = new ExtentLink();
link.setLinkText("Link Text goes here");
link.setLinkUrl("http://somedomain.com");
test.log(Status.INFO, link);
//...
//..
// Now Save report
extent.flush();
Conclusion:
You can easily customize ExtentReport by adding any HTML object like Links, Label, Tables, Image with the help of "Markup" class.