Skip to content

Commit 5bc4aeb

Browse files
author
Denys Zaiats
committed
[issue-24] - fix for collecting results
1 parent 764d9ec commit 5bc4aeb

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/main/java/util/general/HtmlReportBuilder.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@
2121
import java.nio.charset.StandardCharsets;
2222
import java.text.SimpleDateFormat;
2323
import java.util.Date;
24+
import java.util.List;
2425

2526
import static util.validator.Constants.*;
2627

2728

2829
public class HtmlReportBuilder {
2930

3031
private final Logger LOG = Logger.getLogger(HtmlReportBuilder.class);
32+
private List<String> jsonFiles;
3133

32-
public void buildReport(String reportName) throws IOException, ParseException, InterruptedException {
34+
public void buildReport(String reportName, List<String> jsonFiles) throws IOException, ParseException, InterruptedException {
35+
this.jsonFiles = jsonFiles;
3336
writeReport(reportName);
3437
}
3538

36-
public void buildReport() throws IOException, ParseException, InterruptedException {
39+
public void buildReport(List<String> jsonFiles) throws IOException, ParseException, InterruptedException {
40+
this.jsonFiles = jsonFiles;
3741
writeReport("result");
3842
}
3943

@@ -84,7 +88,7 @@ private Html buildHtml() throws IOException, ParseException {
8488

8589
if (listOfFiles != null) {
8690
for (File file : listOfFiles) {
87-
if (file.isFile()) {
91+
if (file.isFile() && jsonFiles.contains(file.getName())) {
8892
JSONParser parser = new JSONParser();
8993
Object obj = parser.parse(new FileReader(file));
9094

@@ -124,6 +128,7 @@ private Html buildHtml() throws IOException, ParseException {
124128
new Style("width: 96%; margin-left:2%"));
125129
}};
126130

131+
jsonFiles.remove(file.getName());
127132
while (!file.delete()) ;
128133
}
129134
}

src/main/java/util/validator/ResponsiveUIValidator.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class ResponsiveUIValidator {
3939
static boolean drawRightOffsetLine = false;
4040
static boolean drawTopOffsetLine = false;
4141
static boolean drawBottomOffsetLine = false;
42-
static boolean isMobileTopBar = false;
42+
private static boolean isMobileTopBar = false;
4343
private static boolean withReport = false;
4444
private static String scenarioName = "Default";
4545
private static Color rootColor = new Color(255, 0, 0, 255);
@@ -50,6 +50,7 @@ public class ResponsiveUIValidator {
5050
private static BufferedImage img;
5151
private static Graphics2D g;
5252
private static JSONArray errorMessage;
53+
private static List<String> jsonFiles = new ArrayList<>();
5354
String rootElementReadableName = "Root Element";
5455
List<WebElement> rootElements;
5556
ResponsiveUIValidator.Units units = PX;
@@ -201,11 +202,13 @@ public boolean validate() {
201202
}
202203

203204
long ms = System.currentTimeMillis();
204-
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(TARGET_AUTOMOTION_JSON + rootElementReadableName.replace(" ", "") + "-automotion" + ms + ".json"), StandardCharsets.UTF_8))) {
205+
String jsonFileName = rootElementReadableName.replace(" ", "") + "-automotion" + ms + ".json";
206+
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(TARGET_AUTOMOTION_JSON + jsonFileName), StandardCharsets.UTF_8))) {
205207
writer.write(jsonResults.toJSONString());
206208
} catch (IOException ex) {
207209
LOG.error("Cannot create json report: " + ex.getMessage());
208210
}
211+
jsonFiles.add(jsonFileName);
209212
try {
210213
File file = new File(TARGET_AUTOMOTION_JSON + rootElementReadableName.replace(" ", "") + "-automotion" + ms + ".json");
211214
if (file.getParentFile().mkdirs()) {
@@ -235,9 +238,9 @@ public boolean validate() {
235238
* Call method to generate HTML report
236239
*/
237240
public void generateReport() {
238-
if (withReport && isAutomotionFolderExists()) {
241+
if (withReport && !jsonFiles.isEmpty()) {
239242
try {
240-
new HtmlReportBuilder().buildReport();
243+
new HtmlReportBuilder().buildReport(jsonFiles);
241244
} catch (IOException | ParseException | InterruptedException e) {
242245
e.printStackTrace();
243246
}
@@ -250,9 +253,9 @@ public void generateReport() {
250253
* @param name
251254
*/
252255
public void generateReport(String name) {
253-
if (withReport && isAutomotionFolderExists()) {
256+
if (withReport && !jsonFiles.isEmpty()) {
254257
try {
255-
new HtmlReportBuilder().buildReport(name);
258+
new HtmlReportBuilder().buildReport(name, jsonFiles);
256259
} catch (IOException | ParseException | InterruptedException e) {
257260
e.printStackTrace();
258261
}

0 commit comments

Comments
 (0)