Skip to content

Commit cf49b01

Browse files
committed
[master] - added validation that elements have different size
1 parent 3fac581 commit cf49b01

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

src/main/java/util/validator/ChunkValidator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public interface ChunkValidator {
1818

1919
ResponsiveUIChunkValidator withSameHeight();
2020

21+
ResponsiveUIChunkValidator withNotSameSize();
22+
23+
ResponsiveUIChunkValidator withNotSameWidth();
24+
25+
ResponsiveUIChunkValidator withNotSameHeight();
26+
2127
ResponsiveUIChunkValidator sameRightOffset();
2228

2329
ResponsiveUIChunkValidator sameLeftOffset();

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,39 @@ public ResponsiveUIChunkValidator withSameHeight() {
9797
return this;
9898
}
9999

100+
/**
101+
* Verify that elements in the list have not the same size
102+
*
103+
* @return ResponsiveUIChunkValidator
104+
*/
105+
@Override
106+
public ResponsiveUIChunkValidator withNotSameSize() {
107+
validateNotSameSize(rootElements, 0);
108+
return this;
109+
}
110+
111+
/**
112+
* Verify that elements in the list have not the same width
113+
*
114+
* @return ResponsiveUIChunkValidator
115+
*/
116+
@Override
117+
public ResponsiveUIChunkValidator withNotSameWidth() {
118+
validateNotSameSize(rootElements, 1);
119+
return this;
120+
}
121+
122+
/**
123+
* Verify that elements in the list have not the same height
124+
*
125+
* @return ResponsiveUIChunkValidator
126+
*/
127+
@Override
128+
public ResponsiveUIChunkValidator withNotSameHeight() {
129+
validateNotSameSize(rootElements, 2);
130+
return this;
131+
}
132+
100133
/**
101134
* Verify that elements in the list have the right offset
102135
*

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,44 @@ void validateSameSize(List<WebElement> elements, int type) {
541541
}
542542
}
543543

544+
void validateNotSameSize(WebElement element, String readableName) {
545+
if (!element.equals(rootElement)) {
546+
int h = element.getSize().getHeight();
547+
int w = element.getSize().getWidth();
548+
if (h == heightRoot && w == widthRoot) {
549+
putJsonDetailsWithElement(String.format("Element '%s' has the same size as %s. Size of '%s' is %spx x %spx. Size of element is %spx x %spx", rootElementReadableName, readableName, rootElementReadableName, widthRoot, heightRoot, w, h), element);
550+
}
551+
}
552+
}
553+
554+
void validateNotSameSize(List<WebElement> elements, int type) {
555+
for (int i = 0; i < elements.size() - 1; i++) {
556+
int h1 = elements.get(i).getSize().getHeight();
557+
int w1 = elements.get(i).getSize().getWidth();
558+
int h2 = elements.get(i + 1).getSize().getHeight();
559+
int w2 = elements.get(i + 1).getSize().getWidth();
560+
switch (type) {
561+
case 0:
562+
if (h1 == h2 && w1 == w2) {
563+
putJsonDetailsWithElement(String.format("Element #%d has same size. Element size is: [%d, %d]", (i + 1), elements.get(i).getSize().width, elements.get(i).getSize().height), elements.get(i));
564+
putJsonDetailsWithElement(String.format("Element #%d has same size. Element size is: [%d, %d]", (i + 2), elements.get(i + 1).getSize().width, elements.get(i + 1).getSize().height), elements.get(i + 1));
565+
}
566+
break;
567+
case 1:
568+
if (w1 == w2) {
569+
putJsonDetailsWithElement(String.format("Element #%d has same width. Element width is: [%d, %d]", (i + 1), elements.get(i).getSize().width, elements.get(i).getSize().height), elements.get(i));
570+
putJsonDetailsWithElement(String.format("Element #%d has same width. Element width is: [%d, %d]", (i + 2), elements.get(i + 1).getSize().width, elements.get(i + 1).getSize().height), elements.get(i + 1));
571+
}
572+
break;
573+
case 2:
574+
if (h1 == h2) {
575+
putJsonDetailsWithElement(String.format("Element #%d has same height. Element height is: [%d, %d]", (i + 1), elements.get(i).getSize().width, elements.get(i).getSize().height), elements.get(i));
576+
putJsonDetailsWithElement(String.format("Element #%d has same height. Element height is: [%d, %d]", (i + 2), elements.get(i + 1).getSize().width, elements.get(i + 1).getSize().height), elements.get(i + 1));
577+
}
578+
}
579+
}
580+
}
581+
544582
void validateBelowElement(WebElement element, int minMargin, int maxMargin) {
545583
int yBelowElement = element.getLocation().getY();
546584
int marginBetweenRoot = yBelowElement - yRoot + heightRoot;

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,33 @@ public UIValidator sameSizeAs(List<WebElement> elements) {
439439
return this;
440440
}
441441

442+
/**
443+
* Verify that element has not the same size as specified element
444+
*
445+
* @param element
446+
* @param readableName
447+
* @return UIValidator
448+
*/
449+
@Override
450+
public UIValidator notSameSizeAs(WebElement element, String readableName) {
451+
validateNotSameSize(element, readableName);
452+
return this;
453+
}
454+
455+
/**
456+
* Verify that element has not the same size as every element in the list
457+
*
458+
* @param elements
459+
* @return UIValidator
460+
*/
461+
@Override
462+
public UIValidator notSameSizeAs(List<WebElement> elements) {
463+
for (WebElement element : elements) {
464+
validateNotSameSize(element, getFormattedMessage(element));
465+
}
466+
return this;
467+
}
468+
442469
/**
443470
* Verify that height of element is in range
444471
*

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ interface Validator {
6868

6969
UIValidator sameSizeAs(List<WebElement> elements);
7070

71+
UIValidator notSameSizeAs(WebElement element, String readableName);
72+
73+
UIValidator notSameSizeAs(List<WebElement> elements);
74+
7175
UIValidator heightBetween(int min, int max);
7276

7377
UIValidator minOffset(int top, int right, int bottom, int left);

0 commit comments

Comments
 (0)