Skip to content

Commit ddbb180

Browse files
committed
[1.4.2-minor fixes] - common fixes
1 parent 6a5edb2 commit ddbb180

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed

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

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,15 @@ public boolean validate() {
177177
if (!errorMessage.isEmpty()) {
178178
jsonResults.put(ERROR_KEY, true);
179179
jsonResults.put(DETAILS, errorMessage);
180-
}
181180

182-
if (withReport && !errorMessage.isEmpty()) {
183-
try {
184-
screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
185-
img = ImageIO.read(screenshot);
186-
} catch (Exception e) {
187-
LOG.error("Failed to create screenshot file: " + e.getMessage());
188-
}
181+
if (withReport) {
182+
try {
183+
screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
184+
img = ImageIO.read(screenshot);
185+
} catch (Exception e) {
186+
LOG.error("Failed to create screenshot file: " + e.getMessage());
187+
}
189188

190-
if (!errorMessage.isEmpty()) {
191189
JSONObject rootDetails = new JSONObject();
192190
rootDetails.put(X, xRoot);
193191
rootDetails.put(Y, yRoot);
@@ -199,32 +197,32 @@ public boolean validate() {
199197
jsonResults.put(TIME_EXECUTION, String.valueOf(System.currentTimeMillis() - startTime) + " milliseconds");
200198
jsonResults.put(ELEMENT_NAME, rootElementReadableName);
201199
jsonResults.put(SCREENSHOT, rootElementReadableName.replace(" ", "") + "-" + screenshot.getName());
202-
}
203200

204-
long ms = System.currentTimeMillis();
205-
String uuid = Helper.getGeneratedStringWithLength(7);
206-
String jsonFileName = rootElementReadableName.replace(" ", "") + "-automotion" + ms + uuid + ".json";
207-
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(TARGET_AUTOMOTION_JSON + jsonFileName), StandardCharsets.UTF_8))) {
208-
writer.write(jsonResults.toJSONString());
209-
} catch (IOException ex) {
210-
LOG.error("Cannot create json report: " + ex.getMessage());
211-
}
212-
jsonFiles.add(jsonFileName);
213-
try {
214-
File file = new File(TARGET_AUTOMOTION_JSON + rootElementReadableName.replace(" ", "") + "-automotion" + ms + uuid + ".json");
215-
if (file.getParentFile().mkdirs()) {
216-
if (file.createNewFile()) {
217-
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
218-
writer.write(jsonResults.toJSONString());
219-
writer.close();
201+
long ms = System.currentTimeMillis();
202+
String uuid = Helper.getGeneratedStringWithLength(7);
203+
String jsonFileName = rootElementReadableName.replace(" ", "") + "-automotion" + ms + uuid + ".json";
204+
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(TARGET_AUTOMOTION_JSON + jsonFileName), StandardCharsets.UTF_8))) {
205+
writer.write(jsonResults.toJSONString());
206+
} catch (IOException ex) {
207+
LOG.error("Cannot create json report: " + ex.getMessage());
208+
}
209+
jsonFiles.add(jsonFileName);
210+
try {
211+
File file = new File(TARGET_AUTOMOTION_JSON + rootElementReadableName.replace(" ", "") + "-automotion" + ms + uuid + ".json");
212+
if (file.getParentFile().mkdirs()) {
213+
if (file.createNewFile()) {
214+
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
215+
writer.write(jsonResults.toJSONString());
216+
writer.close();
217+
}
220218
}
219+
} catch (IOException e) {
220+
e.printStackTrace();
221221
}
222-
} catch (IOException e) {
223-
e.printStackTrace();
224-
}
225222

226-
if ((boolean) jsonResults.get(ERROR_KEY)) {
227-
drawScreenshot();
223+
if ((boolean) jsonResults.get(ERROR_KEY)) {
224+
drawScreenshot();
225+
}
228226
}
229227
}
230228
} else {
@@ -320,7 +318,7 @@ void validateGridAlignment(int columns, int rows) {
320318
int mapSize = map.size();
321319
if (rows > 0) {
322320
if (mapSize != rows) {
323-
putJsonDetailsWithoutElement("Elements in a grid are not aligned properly. Looks like grid has wrong amount of rows. Expected is " + rows + ". Actual is " + mapSize + "");
321+
putJsonDetailsWithoutElement(String.format("Elements in a grid are not aligned properly. Looks like grid has wrong amount of rows. Expected is %d. Actual is %d", rows, mapSize));
324322
}
325323
}
326324

@@ -330,7 +328,7 @@ void validateGridAlignment(int columns, int rows) {
330328
if (rowCount <= mapSize) {
331329
int actualInARow = entry.getValue().intValue();
332330
if (actualInARow != columns) {
333-
putJsonDetailsWithoutElement("Elements in a grid are not aligned properly in row #" + rowCount + ". Expected " + columns + " elements in a row. Actually it's " + actualInARow + "");
331+
putJsonDetailsWithoutElement(String.format("Elements in a grid are not aligned properly in row #%d. Expected %d elements in a row. Actually it's %d", rowCount, columns, actualInARow));
334332
}
335333
rowCount++;
336334
}
@@ -342,31 +340,31 @@ void validateGridAlignment(int columns, int rows) {
342340
void validateRightOffsetForChunk(List<WebElement> elements) {
343341
for (int i = 0; i < elements.size() - 1; i++) {
344342
if (!elementsHaveEqualLeftRightOffset(false, elements.get(i), elements.get(i + 1))) {
345-
putJsonDetailsWithElement("Element #" + (i + 1) + " has not the same right offset as element #" + (i + 2) + "", elements.get(i + 1));
343+
putJsonDetailsWithElement(String.format("Element #%d has not the same right offset as element #%d", i + 1, i + 2), elements.get(i + 1));
346344
}
347345
}
348346
}
349347

350348
void validateLeftOffsetForChunk(List<WebElement> elements) {
351349
for (int i = 0; i < elements.size() - 1; i++) {
352350
if (!elementsHaveEqualLeftRightOffset(true, elements.get(i), elements.get(i + 1))) {
353-
putJsonDetailsWithElement("Element #" + (i + 1) + " has not the same left offset as element #" + (i + 2) + "", elements.get(i + 1));
351+
putJsonDetailsWithElement(String.format("Element #%d has not the same left offset as element #%d", i + 1, i + 2), elements.get(i + 1));
354352
}
355353
}
356354
}
357355

358356
void validateTopOffsetForChunk(List<WebElement> elements) {
359357
for (int i = 0; i < elements.size() - 1; i++) {
360358
if (!elementsHaveEqualTopBottomOffset(true, elements.get(i), elements.get(i + 1))) {
361-
putJsonDetailsWithElement("Element #" + (i + 1) + " has not the same top offset as element #" + (i + 2) + "", elements.get(i + 1));
359+
putJsonDetailsWithElement(String.format("Element #%d has not the same top offset as element #%d", i + 1, i + 2), elements.get(i + 1));
362360
}
363361
}
364362
}
365363

366364
void validateBottomOffsetForChunk(List<WebElement> elements) {
367365
for (int i = 0; i < elements.size() - 1; i++) {
368366
if (!elementsHaveEqualTopBottomOffset(false, elements.get(i), elements.get(i + 1))) {
369-
putJsonDetailsWithElement("Element #" + (i + 1) + " has not the same bottom offset as element #" + (i + 2) + "", elements.get(i + 1));
367+
putJsonDetailsWithElement(String.format("Element #%d has not the same bottom offset as element #%d", i + 1, i + 2), elements.get(i + 1));
370368
}
371369
}
372370
}

src/main/java/util/validator/UIValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public UIValidator withLeftElement(WebElement element) {
4848
}
4949

5050
/**
51-
* // Verify that element which located left to is correct with specified margins
51+
* Verify that element which located left to is correct with specified margins
5252
*
5353
* @param element
5454
* @param minMargin

0 commit comments

Comments
 (0)