Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This is JAVA library for the running of mobile, web or API automated tests.
<dependency>
<groupId>net.itarray</groupId>
<artifactId>automotion</artifactId>
<version>1.4.1</version>
<version>LATEST</version>
</dependency>

### Steps of adding to the project ###
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/util/general/SystemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static util.validator.Constants.TARGET_AUTOMOTION_JSON;

public class SystemHelper {
public static boolean isRetinaDisplay(Graphics2D g) {
public static boolean isRetinaDisplay() {
boolean isRetina = false;
try {
GraphicsDevice graphicsDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
Expand Down
86 changes: 64 additions & 22 deletions src/main/java/util/validator/ResponsiveUIValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class ResponsiveUIValidator implements Validator {
private static boolean withReport = false;
private static long startTime;
private static String scenarioName = "Default";
private static Color rootColor = Color.RED;
private static Color highlightedElementsColor = Color.MAGENTA;
private static Color linesColor = Color.ORANGE;
private WebDriver driver;
private String rootElementReadableName = "Root Element";
private WebElement rootElement;
Expand Down Expand Up @@ -63,6 +66,18 @@ public ResponsiveUIValidator(WebDriver driver) {
errorMessage = new JSONArray();
}

public void setColorForRootElement(Color color) {
rootColor = color;
}

public void setColorForHighlightedElements(Color color) {
highlightedElementsColor = color;
}

public void setLinesColor(Color color) {
linesColor = color;
}

@Override
public ResponsiveUIValidator init() {
return new ResponsiveUIValidator(driver);
Expand Down Expand Up @@ -496,7 +511,7 @@ public void generateReport(String name) {
private void drawScreenshot() {
g = img.createGraphics();

drawRoot(Color.RED);
drawRoot(rootColor);

for (Object obj : errorMessage) {
JSONObject det = (JSONObject) obj;
Expand All @@ -509,9 +524,9 @@ private void drawScreenshot() {
float width = (float) numE.get(WIDTH);
float height = (float) numE.get(HEIGHT);

g.setColor(Color.MAGENTA);
g.setColor(highlightedElementsColor);
g.setStroke(new BasicStroke(2));
if (SystemHelper.isRetinaDisplay(g) && isChrome()) {
if (SystemHelper.isRetinaDisplay() && isChrome()) {
g.drawRect(2 * (int) x, 2 * (int) y, 2 * (int) width, 2 * (int) height);
} else {
g.drawRect((int) x, (int) y, (int) width, (int) height);
Expand Down Expand Up @@ -710,8 +725,8 @@ private void validateSameSize(List<WebElement> elements) {
int h2 = elements.get(i + 1).getSize().getHeight();
int w2 = elements.get(i + 1).getSize().getWidth();
if (h1 != h2 || w1 != w2) {
putJsonDetailsWithElement("Elements in a grid have different size.", elements.get(i));
putJsonDetailsWithElement("Elements in a grid have different size.", elements.get(i + 1));
putJsonDetailsWithElement("Element #" + i + " has different size in a grid.", elements.get(i));
putJsonDetailsWithElement("Element #" + (i + 1) + " has different size in a grid.", elements.get(i + 1));
}
}
}
Expand Down Expand Up @@ -812,17 +827,41 @@ private void validateLeftElement(WebElement leftElement) {
}
}

private boolean elementsAreOverlappedOnBorder(WebElement rootElement, WebElement elementOverlapWith) {
Point elLoc = elementOverlapWith.getLocation();
Dimension elSize = elementOverlapWith.getSize();
int xRoot = rootElement.getLocation().x;
int yRoot = rootElement.getLocation().y;
int widthRoot = rootElement.getSize().width;
int heightRoot = rootElement.getSize().height;

int sqRootElement = (xRoot + widthRoot) * (yRoot + heightRoot);
int sqElement = (elLoc.x + elSize.width) * (elLoc.y + elSize.height);

int sqCommon = 0;
if ((xRoot < elLoc.x && yRoot == elLoc.y) || (yRoot < elLoc.y && xRoot == elLoc.x)) {
sqCommon = (xRoot + widthRoot + elSize.width) + (yRoot + heightRoot + elSize.height);
} else if ((elLoc.x < xRoot && yRoot == elLoc.y) || (elLoc.y < yRoot && xRoot == elLoc.x)) {
sqCommon = (elLoc.x + elSize.width + widthRoot) * (elLoc.y + elSize.height + heightRoot);
}

return sqCommon - sqElement >= sqRootElement;
}

private boolean elementsAreOverlapped(WebElement elementOverlapWith) {
Point elLoc = elementOverlapWith.getLocation();
Dimension elSize = elementOverlapWith.getSize();
return ((xRoot > elLoc.x && yRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
return ((xRoot >= elLoc.x && yRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
|| (xRoot + widthRoot > elLoc.x && yRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
|| (xRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot + heightRoot < elLoc.y + elSize.height)
|| (xRoot + widthRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot + widthRoot < elLoc.y + elSize.height)) ||
((elLoc.x > xRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot)
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot)
|| (elLoc.x > xRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot + heightRoot)
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + widthRoot));
|| (xRoot + widthRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot + widthRoot < elLoc.y + elSize.height))

|| ((elLoc.x > xRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot)
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot)
|| (elLoc.x > xRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot + heightRoot)
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + widthRoot))

|| elementsAreOverlappedOnBorder(rootElement, elementOverlapWith);
}

private boolean elementsAreOverlapped(WebElement rootElement, WebElement elementOverlapWith) {
Expand All @@ -836,11 +875,14 @@ private boolean elementsAreOverlapped(WebElement rootElement, WebElement element
return ((xRoot > elLoc.x && yRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
|| (xRoot + widthRoot > elLoc.x && yRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
|| (xRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot + heightRoot < elLoc.y + elSize.height)
|| (xRoot + widthRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot + widthRoot < elLoc.y + elSize.height)) ||
((elLoc.x > xRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot)
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot)
|| (elLoc.x > xRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot + heightRoot)
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + widthRoot));
|| (xRoot + widthRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot + widthRoot < elLoc.y + elSize.height))

|| ((elLoc.x > xRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot)
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot)
|| (elLoc.x > xRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot + heightRoot)
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + widthRoot))

|| elementsAreOverlappedOnBorder(rootElement, elementOverlapWith);
}

private boolean elementsHasEqualLeftRightOffset(boolean isLeft, WebElement elementToCompare) {
Expand Down Expand Up @@ -868,38 +910,38 @@ private boolean elementsHasEqualTopBottomOffset(boolean isTop, WebElement elemen
private void drawRoot(Color color) {
g.setColor(color);
g.setStroke(new BasicStroke(2));
if (SystemHelper.isRetinaDisplay(g) && isChrome()) {
if (SystemHelper.isRetinaDisplay() && isChrome()) {
g.drawRect(2 * xRoot, 2 * yRoot, 2 * widthRoot, 2 * heightRoot);
} else {
g.drawRect(xRoot, yRoot, widthRoot, heightRoot);
}

Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{9}, 0);
g.setStroke(dashed);
g.setColor(Color.ORANGE);
g.setColor(linesColor);
if (drawLeftOffsetLine) {
if (SystemHelper.isRetinaDisplay(g) && isChrome()) {
if (SystemHelper.isRetinaDisplay() && isChrome()) {
g.drawLine(2 * xRoot, 0, 2 * xRoot, 2 * img.getHeight());
} else {
g.drawLine(xRoot, 0, xRoot, img.getHeight());
}
}
if (drawRightOffsetLine) {
if (SystemHelper.isRetinaDisplay(g) && isChrome()) {
if (SystemHelper.isRetinaDisplay() && isChrome()) {
g.drawLine(2 * (xRoot + widthRoot), 0, 2 * (xRoot + widthRoot), 2 * img.getHeight());
} else {
g.drawLine(xRoot + widthRoot, 0, xRoot + widthRoot, img.getHeight());
}
}
if (drawTopOffsetLine) {
if (SystemHelper.isRetinaDisplay(g) && isChrome()) {
if (SystemHelper.isRetinaDisplay() && isChrome()) {
g.drawLine(0, 2 * yRoot, 2 * img.getWidth(), 2 * yRoot);
} else {
g.drawLine(0, yRoot, img.getWidth(), yRoot);
}
}
if (drawBottomOffsetLine) {
if (SystemHelper.isRetinaDisplay(g) && isChrome()) {
if (SystemHelper.isRetinaDisplay() && isChrome()) {
g.drawLine(0, 2 * (yRoot + heightRoot), 2 * img.getWidth(), 2 * (yRoot + heightRoot));
} else {
g.drawLine(0, yRoot + heightRoot, img.getWidth(), yRoot + heightRoot);
Expand Down