1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package dev.aherscu.qa.jgiven.reporter;
18
19 import static dev.aherscu.qa.testing.utils.FileUtilsExtensions.*;
20 import static org.apache.commons.io.FilenameUtils.*;
21 import static org.xhtmlrenderer.simple.PDFRenderer.*;
22
23 import org.testng.xml.*;
24
25 import com.tngtech.jgiven.report.json.*;
26 import com.tngtech.jgiven.report.model.*;
27
28 import lombok.*;
29 import lombok.experimental.*;
30 import lombok.extern.slf4j.*;
31
32
33
34
35 @SuperBuilder(toBuilder = true)
36 @NoArgsConstructor(force = true)
37 @Slf4j
38 @ToString(callSuper = true)
39 public class QaJGivenPerClassReporter
40 extends
41 AbstractQaJgivenReporter<ReportModel, QaJGivenPerClassReporter> {
42
43 public static final String DEFAULT_TEMPLATE_RESOURCE =
44 "/qa-jgiven-perclass-reporter.html";
45
46
47
48
49
50
51
52
53
54 @Override
55 protected QaJGivenPerClassReporter with(final XmlSuite xmlSuite) {
56 return ((QaJGivenPerClassReporter) super.with(xmlSuite))
57 .toBuilder()
58 .templateResource(templateResourceParamFrom(xmlSuite,
59 DEFAULT_TEMPLATE_RESOURCE))
60 .build();
61 }
62
63
64
65
66
67 @Override
68 @SneakyThrows
69 public void generate() {
70 for (val reportModelFile : listJGivenReports()) {
71
72 log.debug("reading " + reportModelFile);
73
74 val targetReportFile = reportFile(reportModelFile,
75 EXTENSION_SEPARATOR_STR + getExtension(templateResource));
76 try (val reportWriter = fileWriter(targetReportFile)) {
77 template()
78 .execute(reportModel(targetReportFile)
79 .toBuilder()
80 .jgivenReport(new ScenarioJsonReader()
81 .apply(reportModelFile))
82 .screenshotScale(screenshotScale)
83 .datePattern(datePattern)
84 .build(),
85 reportWriter);
86 }
87
88
89 if (pdf) {
90 renderToPDF(
91 reportFile(reportModelFile, ".html"),
92 reportFile(reportModelFile, ".pdf")
93 .getAbsolutePath());
94 }
95 }
96 }
97 }