Skip to content

Commit 0262353

Browse files
committed
[30] - added validation that element in container with specified paddings
1 parent 71d0f6c commit 0262353

File tree

6 files changed

+100
-10
lines changed

6 files changed

+100
-10
lines changed

src/main/java/util/validator/ResponsiveUIChunkValidator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.openqa.selenium.WebDriver;
44
import org.openqa.selenium.WebElement;
5+
import util.validator.properties.Padding;
56

67
import java.util.List;
78

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.openqa.selenium.Point;
1313
import util.driver.PageValidator;
1414
import util.general.HtmlReportBuilder;
15+
import util.validator.properties.Padding;
1516

1617
import javax.imageio.ImageIO;
1718
import java.awt.*;
@@ -22,7 +23,6 @@
2223
import java.util.Arrays;
2324
import java.util.List;
2425
import java.util.Map;
25-
import java.util.concurrent.ConcurrentHashMap;
2626
import java.util.concurrent.ConcurrentSkipListMap;
2727
import java.util.concurrent.atomic.AtomicLong;
2828

@@ -335,7 +335,7 @@ void validateGridAlignment(int columns, int rows) {
335335
if (rowCount <= mapSize) {
336336
int actualInARow = entry.getValue().intValue();
337337
if (actualInARow != columns) {
338-
errorLastLine ++;
338+
errorLastLine++;
339339
if (errorLastLine > 1) {
340340
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));
341341
}
@@ -580,7 +580,7 @@ void validateNotSameSize(List<WebElement> elements, int type) {
580580
}
581581

582582
void validateBelowElement(WebElement element, int minMargin, int maxMargin) {
583-
int yBelowElement = element.getLocation().getY();
583+
int yBelowElement = element.getLocation().y;
584584
int marginBetweenRoot = yBelowElement - yRoot + heightRoot;
585585
if (marginBetweenRoot < minMargin || marginBetweenRoot > maxMargin) {
586586
putJsonDetailsWithElement(String.format("Below element aligned not properly. Expected margin should be between %spx and %spx. Actual margin is %spx", minMargin, maxMargin, marginBetweenRoot), element);
@@ -598,8 +598,8 @@ void validateBelowElement(WebElement element) {
598598
}
599599

600600
void validateAboveElement(WebElement element, int minMargin, int maxMargin) {
601-
int yAboveElement = element.getLocation().getY();
602-
int heightAboveElement = element.getSize().getHeight();
601+
int yAboveElement = element.getLocation().y;
602+
int heightAboveElement = element.getSize().height;
603603
int marginBetweenRoot = yRoot - yAboveElement + heightAboveElement;
604604
if (marginBetweenRoot < minMargin || marginBetweenRoot > maxMargin) {
605605
putJsonDetailsWithElement(String.format("Above element aligned not properly. Expected margin should be between %spx and %spx. Actual margin is %spx", minMargin, maxMargin, marginBetweenRoot), element);
@@ -617,7 +617,7 @@ void validateAboveElement(WebElement element) {
617617
}
618618

619619
void validateRightElement(WebElement element, int minMargin, int maxMargin) {
620-
int xRightElement = element.getLocation().getX();
620+
int xRightElement = element.getLocation().x;
621621
int marginBetweenRoot = xRightElement - xRoot + widthRoot;
622622
if (marginBetweenRoot < minMargin || marginBetweenRoot > maxMargin) {
623623
putJsonDetailsWithElement(String.format("Right element aligned not properly. Expected margin should be between %spx and %spx. Actual margin is %spx", minMargin, maxMargin, marginBetweenRoot), element);
@@ -635,8 +635,8 @@ void validateRightElement(WebElement element) {
635635
}
636636

637637
void validateLeftElement(WebElement leftElement, int minMargin, int maxMargin) {
638-
int xLeftElement = leftElement.getLocation().getX();
639-
int widthLeftElement = leftElement.getSize().getWidth();
638+
int xLeftElement = leftElement.getLocation().x;
639+
int widthLeftElement = leftElement.getSize().width;
640640
int marginBetweenRoot = xRoot - xLeftElement + widthLeftElement;
641641
if (marginBetweenRoot < minMargin || marginBetweenRoot > maxMargin) {
642642
putJsonDetailsWithElement(String.format("Left element aligned not properly. Expected margin should be between %spx and %spx. Actual margin is %spx", minMargin, maxMargin, marginBetweenRoot), leftElement);
@@ -884,6 +884,27 @@ void validateInsideOfContainer(WebElement element, String readableContainerName)
884884
}
885885
}
886886

887+
void validateInsideOfContainer(WebElement element, String readableContainerName, Padding padding) {
888+
validateInsideOfContainer(element, readableContainerName);
889+
int paddingTop = element.getLocation().x - xRoot;
890+
int paddingRight = element.getLocation().y - yRoot;
891+
int paddingBottom = yRoot - element.getLocation().y;
892+
int paddingLeft = xRoot - element.getLocation().x;
893+
894+
int top = getConvertedInt(padding.getTop(), false);
895+
int right = getConvertedInt(padding.getRight(), true);
896+
int bottom = getConvertedInt(padding.getBottom(), false);
897+
int left = getConvertedInt(padding.getLeft(), true);
898+
899+
if ((paddingTop != top && top > -1)
900+
|| (paddingRight != right && right > -1)
901+
|| (paddingBottom != bottom && bottom > -1)
902+
|| (paddingLeft != left && left > -1)) {
903+
putJsonDetailsWithElement(String.format("Padding of element '%s' is incorrect. Expected padding: top[%d], right[%d], bottom[%d], left[%d]. Actual padding: top[%d], right[%d], bottom[%d], left[%d]",
904+
rootElementReadableName, top, right, bottom, left, paddingTop, paddingRight, paddingBottom, paddingLeft), element);
905+
}
906+
}
907+
887908
private int getLeftOffset(WebElement element) {
888909
return element.getLocation().x;
889910
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.openqa.selenium.WebDriver;
55
import org.openqa.selenium.WebElement;
66
import util.general.SystemHelper;
7+
import util.validator.properties.Padding;
78

89
import java.util.List;
910

@@ -43,7 +44,6 @@ public UIValidator changeMetricsUnitsTo(Units units) {
4344
@Override
4445
public UIValidator withLeftElement(WebElement element) {
4546
validateLeftElement(element);
46-
4747
return this;
4848
}
4949

@@ -58,7 +58,6 @@ public UIValidator withLeftElement(WebElement element) {
5858
@Override
5959
public UIValidator withLeftElement(WebElement element, int minMargin, int maxMargin) {
6060
validateLeftElement(element, getConvertedInt(minMargin, true), getConvertedInt(maxMargin, true));
61-
6261
return this;
6362
}
6463

@@ -596,4 +595,10 @@ public UIValidator insideOf(WebElement containerElement, String readableContaine
596595
validateInsideOfContainer(containerElement, readableContainerName);
597596
return this;
598597
}
598+
599+
@Override
600+
public UIValidator insideOf(WebElement containerElement, String readableContainerName, Padding padding) {
601+
validateInsideOfContainer(containerElement, readableContainerName, padding);
602+
return this;
603+
}
599604
}

src/main/java/util/validator/Validator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package util.validator;
22

33
import org.openqa.selenium.WebElement;
4+
import util.validator.properties.Padding;
45

56
import java.util.List;
67

@@ -88,4 +89,6 @@ interface Validator {
8889

8990
UIValidator insideOf(WebElement containerElement, String readableContainerName);
9091

92+
UIValidator insideOf(WebElement containerElement, String readableContainerName, Padding padding);
93+
9194
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package util.validator.properties;
2+
3+
/**
4+
* Created by ZayCo on 03/03/17.
5+
*/
6+
public class Padding {
7+
8+
private int top = -1;
9+
private int right = -1;
10+
private int bottom = -1;
11+
private int left = -1;
12+
13+
public Padding(int padding) {
14+
top = padding;
15+
right = padding;
16+
bottom = padding;
17+
left = padding;
18+
}
19+
20+
public Padding(int top, int right, int bottom, int left) {
21+
this.top = top;
22+
this.right = right;
23+
this.bottom = bottom;
24+
this.left = left;
25+
}
26+
27+
public int getTop() {
28+
return top;
29+
}
30+
31+
public void setTop(int top) {
32+
this.top = top;
33+
}
34+
35+
public int getRight() {
36+
return right;
37+
}
38+
39+
public void setRight(int right) {
40+
this.right = right;
41+
}
42+
43+
public int getBottom() {
44+
return bottom;
45+
}
46+
47+
public void setBottom(int bottom) {
48+
this.bottom = bottom;
49+
}
50+
51+
public int getLeft() {
52+
return left;
53+
}
54+
55+
public void setLeft(int left) {
56+
this.left = left;
57+
}
58+
}

src/test/java/ResponsiveValidatorTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import util.driver.DriverHelper;
1111
import util.driver.WebDriverFactory;
1212
import util.validator.ResponsiveUIValidator;
13+
import util.validator.properties.Padding;
1314

1415
import java.awt.*;
1516
import java.util.HashMap;
@@ -49,6 +50,7 @@ public void testThatResponsiveValidatorWorks() {
4950
.sameSizeAs(page.gridElements())
5051
.equalLeftRightOffset()
5152
.equalTopBottomOffset()
53+
.insideOf(page.mainContainer(), "Main container", new Padding(10, 50, 10, 20))
5254
.drawMap()
5355
.validate();
5456

0 commit comments

Comments
 (0)