Skip to content

Commit fe9091b

Browse files
author
Denys Zaiats
committed
[improve-html-report] - commit 9
1 parent c8217b3 commit fe9091b

File tree

5 files changed

+112
-5
lines changed

5 files changed

+112
-5
lines changed

pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,16 @@
244244
<version>4.12</version>
245245
<scope>test</scope>
246246
</dependency>
247+
<dependency>
248+
<groupId>org.apache.maven</groupId>
249+
<artifactId>maven-plugin-api</artifactId>
250+
<version>3.0</version>
251+
</dependency>
252+
<dependency>
253+
<groupId>org.apache.maven.plugin-tools</groupId>
254+
<artifactId>maven-plugin-annotations</artifactId>
255+
<version>3.4</version>
256+
<scope>provided</scope>
257+
</dependency>
247258
</dependencies>
248259
</project>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package net.itarray.automotion.internal;
2+
3+
import com.webfirmframework.wffweb.tag.html.Body;
4+
import com.webfirmframework.wffweb.tag.html.Html;
5+
import com.webfirmframework.wffweb.tag.html.TitleTag;
6+
import com.webfirmframework.wffweb.tag.html.attribute.Href;
7+
import com.webfirmframework.wffweb.tag.html.attribute.global.Style;
8+
import com.webfirmframework.wffweb.tag.html.links.A;
9+
import com.webfirmframework.wffweb.tag.html.lists.Li;
10+
import com.webfirmframework.wffweb.tag.html.lists.Ol;
11+
import com.webfirmframework.wffweb.tag.html.metainfo.Head;
12+
import com.webfirmframework.wffweb.tag.htmlwff.NoTag;
13+
import org.apache.maven.plugin.AbstractMojo;
14+
import org.apache.maven.plugin.MojoExecutionException;
15+
import org.apache.maven.plugins.annotations.Mojo;
16+
17+
import java.io.BufferedOutputStream;
18+
import java.io.File;
19+
import java.io.FileOutputStream;
20+
import java.io.IOException;
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
24+
import static net.itarray.automotion.validation.Constants.TARGET_AUTOMOTION;
25+
import static net.itarray.automotion.validation.Constants.TARGET_AUTOMOTION_HTML;
26+
27+
@Mojo(name = "automotion")
28+
public class FinalReportBuilder extends AbstractMojo {
29+
30+
@Override
31+
public void execute() throws MojoExecutionException {
32+
File folder = new File(TARGET_AUTOMOTION_HTML);
33+
File[] listOfFiles = folder.listFiles();
34+
List<String> files = new ArrayList<>();
35+
if (listOfFiles != null) {
36+
for (File file : listOfFiles) {
37+
files.add(file.getName());
38+
}
39+
}
40+
41+
Html html = buildHtml(files);
42+
43+
File report = new File(TARGET_AUTOMOTION + "index.html");
44+
report.getParentFile().mkdirs();
45+
try (FileOutputStream fos = new FileOutputStream(report);
46+
BufferedOutputStream bos = new BufferedOutputStream(fos);) {
47+
48+
html.toOutputStream(bos);
49+
bos.flush();
50+
} catch (IOException e) {
51+
e.printStackTrace();
52+
}
53+
}
54+
55+
private Html buildHtml(List<String> files) {
56+
return new Html(null,
57+
new Style("background-color: #fff")) {{
58+
super.setPrependDocType(true);
59+
new Head(this) {{
60+
new TitleTag(this) {{
61+
new NoTag(this, "Automotion report");
62+
}};
63+
new NoTag(this, "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
64+
new NoTag(this, "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">");
65+
66+
new NoTag(this, "<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js\"></script>");
67+
new NoTag(this, "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" integrity=\"sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u\" crossorigin=\"anonymous\">");
68+
new NoTag(this, "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css\" integrity=\"sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp\" crossorigin=\"anonymous\">");
69+
new NoTag(this, "<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\" integrity=\"sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa\" crossorigin=\"anonymous\"></script>");
70+
}};
71+
72+
new Body(this) {{
73+
new Ol(this) {{
74+
for (String s: files) {
75+
76+
new Li(this) {{
77+
78+
new A(this,
79+
new Href("html/" + s)) {{
80+
new NoTag(this, s);
81+
}};
82+
}};
83+
}
84+
}};
85+
}};
86+
}};
87+
}
88+
}

src/main/java/net/itarray/automotion/internal/HtmlReportBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private void writeReport(String reportName) throws IOException, ParseException {
5858
long ms = System.currentTimeMillis();
5959
String uuid = Helper.getGeneratedStringWithLength(7);
6060

61-
File report = new File(TARGET_AUTOMOTION + reportName.replace(" ", "_") + "-" + ms + uuid + ".html");
61+
File report = new File(TARGET_AUTOMOTION_HTML + reportName.replace(" ", "_") + "-" + ms + uuid + ".html");
6262
report.getParentFile().mkdirs();
6363
try (FileOutputStream fos = new FileOutputStream(report);
6464
BufferedOutputStream bos = new BufferedOutputStream(fos);) {
@@ -245,9 +245,9 @@ private Html buildHtml() throws IOException, ParseException {
245245
new Div(this,
246246
new ClassAttribute("row")) {
247247
{
248-
String bgColor = "background: rgba(0,250,154, 0.5)";
248+
String bgColor = "background: rgba(0,250,154, 0.3)";
249249
if (isFailed) {
250-
bgColor = "background: rgba(240,128,128, 0.5)";
250+
bgColor = "background: rgba(240,128,128, 0.3)";
251251
}
252252
new Div(this,
253253
new Style("margin-top:2px;" + bgColor),
@@ -315,13 +315,13 @@ private Html buildHtml() throws IOException, ParseException {
315315
if (isFailed) {
316316
new Img(this,
317317
new Style("position:relative; left: 0; top:0"),
318-
new Src(String.format("img/%s", jsonObject.get(SCREENSHOT))),
318+
new Src(String.format("../img/%s", jsonObject.get(SCREENSHOT))),
319319
new Alt("screenshot"));
320320
new Img(this,
321321
new Id(screenshotDrawingOverlay.toString()),
322322
new Style("position:absolute; left: 0; top:0;"),
323323
//new Style("position:absolute; left: 0; top:0; display:none;"),
324-
new Src(String.format("img/%s", screenshotDrawingOverlay.toString())),
324+
new Src(String.format("../img/%s", screenshotDrawingOverlay.toString())),
325325
new OnClick("showModal('" + screenshotDrawingOverlay.toString() + "')"),
326326
new Alt("screenshot-overlay"));
327327
}

src/main/java/net/itarray/automotion/validation/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ public class Constants {
1919
public static final String TARGET_AUTOMOTION_JSON = "target/automotion/json/";
2020
public static final String TARGET_AUTOMOTION_IMG = "target/automotion/img/";
2121
public static final String TARGET_AUTOMOTION = "target/automotion/";
22+
public static final String TARGET_AUTOMOTION_HTML = "target/automotion/html/";
2223
}

src/test/java/ResponsiveValidatorNewDSLTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import net.itarray.automotion.internal.FinalReportBuilder;
12
import net.itarray.automotion.tools.driver.WebDriverFactory;
23
import net.itarray.automotion.tools.helpers.EnvironmentHelper;
34
import net.itarray.automotion.validation.ResponsiveUIValidator;
45
import net.itarray.automotion.validation.UISnapshot;
56
import net.itarray.automotion.validation.properties.Padding;
7+
import org.apache.maven.plugin.MojoExecutionException;
68
import org.assertj.core.api.SoftAssertions;
79
import org.junit.After;
810
import org.junit.Ignore;
@@ -149,6 +151,11 @@ public void testThatResponsiveValidatorWorks() {
149151
responsiveUIValidator.generateReport("Home Page");
150152
time("-9-");
151153

154+
try {
155+
new FinalReportBuilder().execute();
156+
} catch (MojoExecutionException e) {
157+
e.printStackTrace();
158+
}
152159
softly.assertAll();
153160
}
154161

0 commit comments

Comments
 (0)