Skip to content

Commit eeac2d7

Browse files
authored
Merge pull request #7 from ITArray/1.4.1-fix
1.4.1 fix
2 parents ffaa175 + 1096909 commit eeac2d7

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This is JAVA library for the running of mobile, web or API automated tests.
88
<dependency>
99
<groupId>net.itarray</groupId>
1010
<artifactId>automotion</artifactId>
11-
<version>1.4.0</version>
11+
<version>1.4.1</version>
1212
</dependency>
1313

1414
### Steps of adding to the project ###

src/main/java/util/general/SystemHelper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package util.general;
22

33
import java.awt.*;
4+
import java.io.File;
45
import java.lang.reflect.Field;
56

7+
import static util.validator.Constants.TARGET_AUTOMOTION_JSON;
8+
69
public class SystemHelper {
710
public static boolean isRetinaDisplay(Graphics2D g) {
811
boolean isRetina = false;
@@ -53,4 +56,10 @@ public static String hexStringToARGB(String hexARGB) throws IllegalArgumentExcep
5356
return String.format("rgb(%d,%d,%d)", intARGB[0], intARGB[1], intARGB[2]);
5457
}
5558
}
59+
60+
public static boolean isAutomotionFolderExists(){
61+
File file = new File(TARGET_AUTOMOTION_JSON);
62+
63+
return file != null && file.exists() && file.isDirectory() && file.list().length > 0;
64+
}
5665
}

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.concurrent.atomic.AtomicLong;
2626

2727
import static environment.EnvironmentFactory.isChrome;
28+
import static util.general.SystemHelper.isAutomotionFolderExists;
2829
import static util.validator.Constants.*;
2930
import static util.validator.ResponsiveUIValidator.Units.PX;
3031

@@ -473,7 +474,7 @@ public boolean validate() {
473474

474475
@Override
475476
public void generateReport() {
476-
if (withReport && (boolean) jsonResults.get(ERROR_KEY)) {
477+
if (withReport && isAutomotionFolderExists()) {
477478
try {
478479
new HtmlReportBuilder().buildReport();
479480
} catch (IOException | ParseException | InterruptedException e) {
@@ -484,7 +485,7 @@ public void generateReport() {
484485

485486
@Override
486487
public void generateReport(String name) {
487-
if (withReport && (boolean) jsonResults.get(ERROR_KEY)) {
488+
if (withReport && isAutomotionFolderExists()) {
488489
try {
489490
new HtmlReportBuilder().buildReport(name);
490491
} catch (IOException | ParseException | InterruptedException e) {
@@ -551,27 +552,30 @@ private void validateGridAlignment(int columns, int rows) {
551552
map.get(y).incrementAndGet();
552553
}
553554

555+
int mapSize = map.size();
554556
if (rows > 0) {
555-
if (map.size() != rows) {
556-
putJsonDetailsWithoutElement("Elements in a grid are not aligned properly.");
557+
if (mapSize != rows) {
558+
putJsonDetailsWithoutElement("Elements in a grid are not aligned properly. Looks like grid has wrong amount of rows. Expected is " + rows + ". Actual is " + mapSize + "");
557559
}
558560
}
559561

560562
if (columns > 0) {
561563
int rowCount = 1;
562564
for (Map.Entry<Integer, AtomicLong> entry : map.entrySet()) {
563-
if (rowCount <= map.size()) {
564-
if (entry.getValue().intValue() != columns) {
565-
putJsonDetailsWithoutElement("Elements in a grid are not aligned properly in row #" + rowCount + ".");
565+
if (rowCount <= mapSize) {
566+
int actualInARow = entry.getValue().intValue();
567+
if (actualInARow != columns) {
568+
putJsonDetailsWithoutElement("Elements in a grid are not aligned properly in row #" + rowCount + ". Expected " + columns + " elements in a row. Actually it's " + actualInARow + "");
566569
}
567570
rowCount++;
568571
}
569572
}
570-
} else {
571-
if (map.size() == rootElements.size()) {
572-
putJsonDetailsWithoutElement("Elements are not aligned in a grid.");
573-
}
574573
}
574+
// else {
575+
// if (map.size() == rootElements.size()) {
576+
// putJsonDetailsWithoutElement("Elements are not aligned in a grid.");
577+
// }
578+
// }
575579
}
576580

577581
// List<WebElement> row = new ArrayList<>();
@@ -728,17 +732,14 @@ private void validateSameSize(WebElement element, String readableName) {
728732
}
729733

730734
private void validateSameSize(List<WebElement> elements) {
731-
for (WebElement el1 : elements) {
732-
for (WebElement el2 : elements) {
733-
if (!el1.equals(el2)) {
734-
int h1 = el1.getSize().getHeight();
735-
int w1 = el1.getSize().getWidth();
736-
int h2 = el2.getSize().getHeight();
737-
int w2 = el2.getSize().getWidth();
738-
if (h1 != h2 || w1 != w2) {
739-
putJsonDetailsWithElement("Elements in a grid have different size.", el1);
740-
}
741-
}
735+
for (int i = 0; i < elements.size() - 1; i ++){
736+
int h1 = elements.get(i).getSize().getHeight();
737+
int w1 = elements.get(i).getSize().getWidth();
738+
int h2 = elements.get(i + 1).getSize().getHeight();
739+
int w2 = elements.get(i + 1).getSize().getWidth();
740+
if (h1 != h2 || w1 != w2) {
741+
putJsonDetailsWithElement("Elements in a grid have different size.", elements.get(i));
742+
putJsonDetailsWithElement("Elements in a grid have different size.", elements.get(i + 1));
742743
}
743744
}
744745
}

0 commit comments

Comments
 (0)