Skip to content

A Complete Example

Anshoo Arora edited this page Aug 13, 2020 · 5 revisions

This document shows a complete example of some of the different approaches you can use to present information.

The example is also available online here.

importcom.aventstack.extentreports.markuputils.MarkupHelper;
importcom.aventstack.extentreports.reporter.ExtentSparkReporter;
publicclassMain {
privatestaticfinalStringCODE1 = "{\n\"theme\": \"standard\",\n\"encoding\": \"utf-8\n}";
privatestaticfinalStringCODE2 = "{\n\"protocol\": \"HTTPS\",\n\"timelineEnabled\": false\n}";
publicstaticvoidmain(String[] args) throwsClassNotFoundException {
ExtentReportsextent = newExtentReports();
ExtentSparkReporterspark = newExtentSparkReporter("target/Spark/Spark.html");
extent.attachReporter(spark);
extent.createTest("ScreenCapture")
.addScreenCaptureFromPath("extent.png")
.pass(MediaEntityBuilder.createScreenCaptureFromPath("extent.png").build());
extent.createTest("LogLevels")
.info("info")
.pass("pass")
.warning("warn")
.skip("skip")
.fail("fail");
extent.createTest("CodeBlock").generateLog(
Status.PASS,
MarkupHelper.createCodeBlock(CODE1, CODE2));
extent.createTest("ParentWithChild")
.createNode("Child")
.pass("This test is created as a toggle as part of a child test of 'ParentWithChild'");
extent.createTest("Tags")
.assignCategory("MyTag")
.pass("The test 'Tags' was assigned by the tag <span class='badge badge-primary'>MyTag</span>");
extent.createTest("Authors")
.assignAuthor("TheAuthor")
.pass("This test 'Authors' was assigned by a special kind of author tag.");
extent.createTest("Devices")
.assignDevice("TheDevice")
.pass("This test 'Devices' was assigned by a special kind of devices tag.");
extent.createTest("Exception! <i class='fa fa-frown-o'></i>")
.fail(newRuntimeException("A runtime exception occurred!"));
extent.flush();
}
}

Clone this wiki locally