Java源码示例:com.aventstack.extentreports.ExtentReports
示例1
private void init() {
//文件夹不存在的话进行创建
File reportDir= new File(OUTPUT_FOLDER);
if(!reportDir.exists()&& !reportDir .isDirectory()){
reportDir.mkdir();
}
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(OUTPUT_FOLDER + FILE_NAME);
// 设置静态文件的DNS
//解决cdn.rawqit.com css访问不了的情况
htmlReporter.config().setResourceCDN(ResourceCDN.EXTENTREPORTS);
htmlReporter.config().setDocumentTitle("api自动化测试报告");
htmlReporter.config().setReportName("api自动化测试报告");
htmlReporter.config().setChartVisibilityOnOpen(true);
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.STANDARD);
htmlReporter.config().setCSS(".node.level-1 ul{ display:none;} .node.level-1.active ul{display:block;}");
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
extent.setReportUsesManualConfiguration(true);
}
示例2
@org.testng.annotations.Test
public void exceptionContext() {
String msg = "An exception has occurred.";
RuntimeException ex = new RuntimeException(msg);
ExtentReports extent = extent();
ExtentTest test = extent.createTest("Test");
NamedAttributeContextManager<ExceptionInfo> context = extent.getReport().getExceptionInfoCtx();
Assert.assertFalse(context.hasItems());
test.fail(ex);
test.assignDevice("x");
Assert.assertTrue(context.hasItems());
Assert.assertTrue(
context.getSet().stream().anyMatch(x -> x.getAttr().getName().equals("java.lang.RuntimeException")));
Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getTestList().size() == 1));
Assert.assertTrue(context.getSet().stream()
.flatMap(x -> x.getTestList().stream())
.anyMatch(x -> x.getName().equals("Test")));
}
示例3
@Test
public void reportContainsTestsAndNodes() {
ExtentReports extent = new ExtentReports();
String path = path();
ExtentSparkReporter spark = new ExtentSparkReporter(path);
extent.attachReporter(spark);
extent.createTest(PARENT)
.createNode(CHILD)
.createNode(GRANDCHILD)
.pass("Pass");
extent.flush();
assertFileExists(path);
Assert.assertEquals(spark.getReport().getTestList().size(), 1);
Assert.assertEquals(spark.getReport().getTestList().get(0).getName(), PARENT);
Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().size(), 1);
Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().get(0).getName(), CHILD);
Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().get(0).getChildren().size(), 1);
Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().get(0).getChildren().get(0).getName(),
GRANDCHILD);
}
示例4
@Test
public void reportContainsTestsAndNodesTags() {
ExtentReports extent = new ExtentReports();
String path = path();
ExtentSparkReporter spark = new ExtentSparkReporter(path);
extent.attachReporter(spark);
extent.createTest(PARENT).assignCategory("Tag1")
.createNode(CHILD).assignCategory("Tag2")
.createNode(GRANDCHILD).assignCategory("Tag3")
.pass("Pass");
extent.flush();
assertFileExists(path);
com.aventstack.extentreports.model.Test t = spark.getReport().getTestList().get(0);
Assert.assertTrue(t.getCategorySet().stream().anyMatch(x -> x.getName().equals("Tag1")));
Assert.assertTrue(t.getChildren().get(0).getCategorySet().stream().anyMatch(x -> x.getName().equals("Tag2")));
Assert.assertTrue(t.getChildren().get(0).getChildren().get(0).getCategorySet().stream()
.anyMatch(x -> x.getName().equals("Tag3")));
}
示例5
@Test
public void reportContainsTestsAndNodesUsers() {
ExtentReports extent = new ExtentReports();
String path = path();
ExtentSparkReporter spark = new ExtentSparkReporter(path);
extent.attachReporter(spark);
extent.createTest(PARENT).assignAuthor("Tag1")
.createNode(CHILD).assignAuthor("Tag2")
.createNode(GRANDCHILD).assignAuthor("Tag3")
.pass("Pass");
extent.flush();
assertFileExists(path);
com.aventstack.extentreports.model.Test t = spark.getReport().getTestList().get(0);
Assert.assertTrue(t.getAuthorSet().stream().anyMatch(x -> x.getName().equals("Tag1")));
Assert.assertTrue(t.getChildren().get(0).getAuthorSet().stream().anyMatch(x -> x.getName().equals("Tag2")));
Assert.assertTrue(t.getChildren().get(0).getChildren().get(0).getAuthorSet().stream()
.anyMatch(x -> x.getName().equals("Tag3")));
}
示例6
@Test
public void reportContainsTestsAndNodesDevices() {
ExtentReports extent = new ExtentReports();
String path = path();
ExtentSparkReporter spark = new ExtentSparkReporter(path);
extent.attachReporter(spark);
extent.createTest(PARENT).assignDevice("Tag1")
.createNode(CHILD).assignDevice("Tag2")
.createNode(GRANDCHILD).assignDevice("Tag3")
.pass("Pass");
extent.flush();
assertFileExists(path);
com.aventstack.extentreports.model.Test t = spark.getReport().getTestList().get(0);
Assert.assertTrue(t.getDeviceSet().stream().anyMatch(x -> x.getName().equals("Tag1")));
Assert.assertTrue(t.getChildren().get(0).getDeviceSet().stream().anyMatch(x -> x.getName().equals("Tag2")));
Assert.assertTrue(t.getChildren().get(0).getChildren().get(0).getDeviceSet().stream()
.anyMatch(x -> x.getName().equals("Tag3")));
}
示例7
@Test
public void statusFilterable() {
ExtentReports extent = new ExtentReports();
String path = path();
ExtentSparkReporter spark = new ExtentSparkReporter(path)
.filter()
.statusFilter()
.as(new Status[]{Status.FAIL})
.apply();
extent.attachReporter(spark);
extent.createTest(PARENT).pass("Pass");
extent.createTest(CHILD).fail("Fail");
extent.flush();
assertFileExists(path);
Assert.assertEquals(spark.getReport().getTestList().size(), 1);
Assert.assertEquals(spark.getReport().getTestList().get(0).getName(), CHILD);
}
示例8
@Test
public void statusFilterableNode() {
ExtentReports extent = new ExtentReports();
String path = path();
ExtentSparkReporter spark = new ExtentSparkReporter(path)
.filter()
.statusFilter()
.as(new Status[]{Status.FAIL})
.apply();
extent.attachReporter(spark);
extent.createTest(PARENT).pass("Pass");
extent.createTest(CHILD).pass("Pass")
.createNode(GRANDCHILD).fail("Fail");
extent.flush();
assertFileExists(path);
Assert.assertEquals(spark.getReport().getTestList().size(), 1);
Assert.assertEquals(spark.getReport().getTestList().get(0).getName(), CHILD);
Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().size(), 1);
Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().get(0).getName(), GRANDCHILD);
}
示例9
@Test
public void testEnglishGherkinKeywords() throws ClassNotFoundException, UnsupportedEncodingException {
ExtentReports extent = extent();
extent.setGherkinDialect("en");
ExtentTest feature = extent.createTest(new GherkinKeyword("Feature"), "Refund item VM");
ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Jeff returns a faulty microwave");
ExtentTest given = scenario.createNode(new GherkinKeyword("Given"), "Jeff has bought a microwave for $100").skip("skip");
ExtentTest and = scenario.createNode(new GherkinKeyword("And"), "he has a receipt").pass("pass");
ExtentTest when = scenario.createNode(new GherkinKeyword("When"), "he returns the microwave").pass("pass");
ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Jeff should be refunded $100").skip("skip");
Assert.assertEquals(feature.getModel().getBddType(), Feature.class);
Assert.assertEquals(scenario.getModel().getBddType(), Scenario.class);
Assert.assertEquals(given.getModel().getBddType(), Given.class);
Assert.assertEquals(and.getModel().getBddType(), And.class);
Assert.assertEquals(when.getModel().getBddType(), When.class);
Assert.assertEquals(then.getModel().getBddType(), Then.class);
}
示例10
@Test
public void testGermanGherkinKeywords() throws ClassNotFoundException, UnsupportedEncodingException {
ExtentReports extent = extent();
extent.setGherkinDialect("de");
ExtentTest feature = extent.createTest(new GherkinKeyword("Funktionalität"), "Refund item VM");
ExtentTest scenario = feature.createNode(new GherkinKeyword("Szenario"), "Jeff returns a faulty microwave");
ExtentTest given = scenario.createNode(new GherkinKeyword("Angenommen"), "Jeff has bought a microwave for $100").skip("skip");
ExtentTest and = scenario.createNode(new GherkinKeyword("Und"), "he has a receipt").pass("pass");
ExtentTest when = scenario.createNode(new GherkinKeyword("Wenn"), "he returns the microwave").pass("pass");
ExtentTest then = scenario.createNode(new GherkinKeyword("Dann"), "Jeff should be refunded $100").skip("skip");
Assert.assertEquals(feature.getModel().getBddType(), Feature.class);
Assert.assertEquals(scenario.getModel().getBddType(), Scenario.class);
Assert.assertEquals(given.getModel().getBddType(), Given.class);
Assert.assertEquals(and.getModel().getBddType(), And.class);
Assert.assertEquals(when.getModel().getBddType(), When.class);
Assert.assertEquals(then.getModel().getBddType(), Then.class);
}
示例11
public void buildReport() {
final ExtentSparkReporter extentSparkReporter = new ExtentSparkReporter(extentReportsProperties.getReportFilename());
if (extentReportsProperties.getXMLConfigFile() != null) {
extentSparkReporter.loadXMLConfig(extentReportsProperties.getXMLConfigFile(), true);
}
final ExtentReports extentReports = new ExtentReports();
extentReports.setReportUsesManualConfiguration(true);
extentReports.attachReporter(extentSparkReporter);
getDistinctFeatureUris().forEach(featureUri -> {
List<Feature> features = featureList.stream().filter(f -> f.getUri().equals(featureUri)).collect(Collectors.toList());
addFeatures(extentReports, features);
});
extentReports.flush();
}
示例12
private void addFeatures(ExtentReports extentReports, List<Feature> features) {
final ExtentTest featureNode = createBddTest(extentReports, features.get(0).getName());
features.forEach(feature -> {
if (feature.getScenarios().size() > 1) {
addFeatureStartAndEndTime(featureNode, feature);
}
for (Scenario scenario : feature.getScenarios()) {
if (scenario.getKeyword().startsWith("Scenario")) {
addScenario(featureNode, scenario);
addScenarioStartAndEndTime(featureNode, scenario);
}
}
});
}
示例13
private void init() {
//文件夹不存在的话进行创建
File reportDir= new File(OUTPUT_FOLDER);
if(!reportDir.exists()&& !reportDir .isDirectory()){
reportDir.mkdir();
}
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(OUTPUT_FOLDER + FILE_NAME);
// 设置静态文件的DNS
//解决cdn.rawqit.com css访问不了的情况
// htmlReporter.config().setResourceCDN(ResourceCDN.EXTENTREPORTS);
htmlReporter.config().setDocumentTitle("api自动化测试报告");
htmlReporter.config().setReportName("api自动化测试报告");
// htmlReporter.config().setChartVisibilityOnOpen(true);
// htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.STANDARD);
htmlReporter.config().setCSS(".node.level-1 ul{ display:none;} .node.level-1.active ul{display:block;}");
// 创建一个KlovReporter对象
ExtentKlovReporter klov = new ExtentKlovReporter();
// 定义MongoDB连接
klov.initMongoDbConnection("localhost", 27017);
// 设置klov服务器URL
klov.initKlovServerConnection("http://localhost");
// 为我们的测试项目提供项目名称
klov.setProjectName("zuozewei-test");
klov.setReportName("1.0");
// 邮件报告名emailable-report.html
File emailReportFile = new File(reportDir, "emailable-report.html");
EmailReporter emailReporter = new EmailReporter(emailReportFile);
extent = new ExtentReports();
extent.attachReporter(htmlReporter,klov,emailReporter);
extent.setReportUsesManualConfiguration(true);
}
示例14
private void init() {
//文件夹不存在的话进行创建
File reportDir= new File(OUTPUT_FOLDER);
if(!reportDir.exists()&& !reportDir .isDirectory()){
reportDir.mkdir();
}
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(OUTPUT_FOLDER + FILE_NAME);
// 设置静态文件的DNS
//解决cdn.rawqit.com css访问不了的情况
// htmlReporter.config().setResourceCDN(ResourceCDN.EXTENTREPORTS);
htmlReporter.config().setDocumentTitle("api自动化测试报告");
htmlReporter.config().setReportName("api自动化测试报告");
// htmlReporter.config().setChartVisibilityOnOpen(true);
// htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.STANDARD);
htmlReporter.config().setCSS(".node.level-1 ul{ display:none;} .node.level-1.active ul{display:block;}");
// 创建一个KlovReporter对象
ExtentKlovReporter klov = new ExtentKlovReporter();
// 定义MongoDB连接
klov.initMongoDbConnection("localhost", 27017);
// 设置klov服务器URL
klov.initKlovServerConnection("http://localhost");
// 为我们的测试项目提供项目名称
klov.setProjectName("zuozewei-test");
klov.setReportName("1.0");
// 邮件报告名emailable-report.html
File emailReportFile = new File(reportDir, "emailable-report.html");
EmailReporter emailReporter = new EmailReporter(emailReportFile);
extent = new ExtentReports();
extent.attachReporter(htmlReporter,klov,emailReporter);
extent.setReportUsesManualConfiguration(true);
}
示例15
/**
* Creates the HTML report, saving all resources (css, js, fonts) in the
* same location, so the report can be viewed without an internet connection
*
* @param offlineMode
* Setting to enable an offline accessible report
*/
public void enableOfflineMode(Boolean offlineMode) {
this.offlineMode = offlineMode;
if (offlineMode && reporter != null) {
File f = Offline.getTargetDirectory(((ExtentSparkReporter) reporter).getFile());
String resPackage = ExtentReports.class.getPackage().getName().replace(".", SEP);
resPackage += SEP + "offline" + SEP;
String[] resx = Offline.combineAll();
ResourceHelper.saveOfflineResources(resPackage, resx, f.getAbsolutePath());
}
}
示例16
@org.testng.annotations.Test
public void authorCtx() {
ExtentReports extent = extent();
ExtentTest test = extent.createTest("Test");
NamedAttributeContextManager<Author> context = extent.getReport().getAuthorCtx();
Assert.assertFalse(context.hasItems());
test.assignAuthor("x");
Assert.assertTrue(context.hasItems());
Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getAttr().getName().equals("x")));
Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getTestList().size() == 1));
Assert.assertTrue(context.getSet().stream()
.flatMap(x -> x.getTestList().stream())
.anyMatch(x -> x.getName().equals("Test")));
}
示例17
@org.testng.annotations.Test
public void categoryCtx() {
ExtentReports extent = extent();
ExtentTest test = extent.createTest("Test");
NamedAttributeContextManager<Category> context = extent.getReport().getCategoryCtx();
Assert.assertFalse(context.hasItems());
test.assignCategory("x");
Assert.assertTrue(context.hasItems());
Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getAttr().getName().equals("x")));
Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getTestList().size() == 1));
Assert.assertTrue(context.getSet().stream()
.flatMap(x -> x.getTestList().stream())
.anyMatch(x -> x.getName().equals("Test")));
}
示例18
@org.testng.annotations.Test
public void deviceCtx() {
ExtentReports extent = extent();
ExtentTest test = extent.createTest("Test");
NamedAttributeContextManager<Device> context = extent.getReport().getDeviceCtx();
Assert.assertFalse(context.hasItems());
test.assignDevice("x");
Assert.assertTrue(context.hasItems());
Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getAttr().getName().equals("x")));
Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getTestList().size() == 1));
Assert.assertTrue(context.getSet().stream()
.flatMap(x -> x.getTestList().stream())
.anyMatch(x -> x.getName().equals("Test")));
}
示例19
@org.testng.annotations.Test
public void testRunnerLogs() {
String[] s = new String[]{"Log 1", "Log 2", "Log 3"};
ExtentReports extent = extent();
List<String> logs = extent.getReport().getLogs();
Assert.assertTrue(logs.isEmpty());
Arrays.stream(s).forEach(x -> extent.addTestRunnerOutput(x));
Assert.assertFalse(logs.isEmpty());
Arrays.stream(s).forEach(x -> Assert.assertTrue(logs.contains(x)));
}
示例20
@Test
public void createsReportWithNoTestsInitPath() {
ExtentReports extent = new ExtentReports();
String path = path();
ExtentSparkReporter spark = new ExtentSparkReporter(path);
extent.attachReporter(spark);
extent.flush();
assertFileExists(path);
}
示例21
@Test
public void createsReportWithNoTestsInitFile() {
ExtentReports extent = new ExtentReports();
String path = path();
ExtentSparkReporter spark = new ExtentSparkReporter(new File(path));
extent.attachReporter(spark);
extent.flush();
assertFileExists(path);
}
示例22
@Test
public void sparkOffline() {
ExtentReports extent = new ExtentReports();
String path = path();
ExtentSparkReporter spark = new ExtentSparkReporter(path);
spark.config().enableOfflineMode(true);
extent.attachReporter(spark);
extent.createTest(PARENT).pass("Pass");
extent.flush();
assertFileExists(path);
Assert.assertTrue(new File(FILE_PATH + "spark/" + SCRIPTS).exists());
Assert.assertTrue(new File(FILE_PATH + "spark/" + STYLESHEET).exists());
}
示例23
@Test
public void disposableNonNull() {
ExtentReports extent = new ExtentReports();
Assert.assertNull(disp);
Assert.assertNull(entity);
extent.attachReporter(new TestReporter());
Assert.assertNotNull(disp);
Assert.assertNull(entity);
extent.flush();
Assert.assertNotNull(disp);
Assert.assertNotNull(entity);
}
示例24
/**
* init method to customize report
*
* @param suite
*/
private void init(ISuite suite) {
File directory = new File(Global_VARS.REPORT_PATH);
if ( !directory.exists() ) {
directory.mkdirs();
}
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(Global_VARS.REPORT_PATH + suite.getName() + ".html");
// report attributes
htmlReporter.config().setDocumentTitle(docTitle);
htmlReporter.config().setReportName(suite.getName().replace("_", " "));
htmlReporter.config().setChartVisibilityOnOpen(false);
htmlReporter.config().setTheme(Theme.STANDARD);
htmlReporter.config().setEncoding("UTF-8");
htmlReporter.config().setProtocol(Protocol.HTTPS);
htmlReporter.config().setTimeStampFormat("MMM-dd-yyyy HH:mm:ss a");
htmlReporter.loadXMLConfig(new File(Global_VARS.REPORT_CONFIG_FILE));
extent = new ExtentReports();
// report system info
extent.setSystemInfo("Browser", Global_VARS.DEF_BROWSER);
extent.setSystemInfo("Environment", Global_VARS.DEF_ENVIRONMENT);
extent.setSystemInfo("Platform", Global_VARS.DEF_PLATFORM);
extent.setSystemInfo("OS Version", System.getProperty("os.version"));
extent.setSystemInfo("Java Version", System.getProperty("java.version"));
extent.setSystemInfo("Selenium Version", seleniumRev);
extent.attachReporter(htmlReporter);
extent.setReportUsesManualConfiguration(true);
}
示例25
public RawEntityConverter(ExtentReports extent) {
this.extent = extent;
}
示例26
private ExtentReports extent() {
return new ExtentReports();
}
示例27
private ExtentReports extent() {
return new ExtentReports();
}
示例28
public static synchronized ExtentReports getInstance() {
return ExtentReportsLoader.INSTANCE;
}
示例29
@SuppressWarnings("unused")
private ExtentReports readResolve() {
return ExtentReportsLoader.INSTANCE;
}
示例30
public static synchronized ExtentReports getInstance() {
return ExtentReportsLoader.INSTANCE;
}