Skip to content

Commit 771fac4

Browse files
committed
[1.4.2-update-error-messages] - cleaning the code
1 parent a485a7b commit 771fac4

File tree

3 files changed

+173
-172
lines changed

3 files changed

+173
-172
lines changed

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

Lines changed: 153 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -456,28 +456,6 @@ void validateSameSize(List<WebElement> elements, int type) {
456456
}
457457
}
458458

459-
void validateInsideOfContainer(WebElement element, String readableContainerName) {
460-
float xContainer = element.getLocation().x;
461-
float yContainer = element.getLocation().y;
462-
float widthContainer = element.getSize().width;
463-
float heightContainer = element.getSize().height;
464-
if (rootElements == null || rootElements.isEmpty()) {
465-
if (xRoot < xContainer || yRoot < yContainer || (xRoot + widthRoot) > (xContainer + widthContainer) || (yRoot + heightRoot) > (yContainer + heightContainer)) {
466-
putJsonDetailsWithElement(String.format("Element '%s' is not inside of '%s'", rootElementReadableName, readableContainerName), element);
467-
}
468-
} else {
469-
for (WebElement el : rootElements) {
470-
float xRoot = el.getLocation().x;
471-
float yRoot = el.getLocation().y;
472-
float widthRoot = el.getSize().width;
473-
float heightRoot = el.getSize().height;
474-
if (xRoot < xContainer || yRoot < yContainer || (xRoot + widthRoot) > (xContainer + widthContainer) || (yRoot + heightRoot) > (yContainer + heightContainer)) {
475-
putJsonDetailsWithElement(String.format("Element is not inside of '%s'", readableContainerName), element);
476-
}
477-
}
478-
}
479-
}
480-
481459
void validateBelowElement(WebElement element, int minMargin, int maxMargin) {
482460
int yBelowElement = element.getLocation().getY();
483461
int marginBetweenRoot = yBelowElement - yRoot + heightRoot;
@@ -552,113 +530,6 @@ void validateLeftElement(WebElement leftElement) {
552530
}
553531
}
554532

555-
private boolean elementsAreOverlappedOnBorder(WebElement rootElement, WebElement elementOverlapWith) {
556-
Point elLoc = elementOverlapWith.getLocation();
557-
Dimension elSize = elementOverlapWith.getSize();
558-
int xRoot = rootElement.getLocation().x;
559-
int yRoot = rootElement.getLocation().y;
560-
int widthRoot = rootElement.getSize().width;
561-
int heightRoot = rootElement.getSize().height;
562-
563-
int sqRootElement = (xRoot + widthRoot) * (yRoot + heightRoot);
564-
int sqElement = (elLoc.x + elSize.width) * (elLoc.y + elSize.height);
565-
566-
int sqCommon = 0;
567-
if ((xRoot < elLoc.x && yRoot == elLoc.y) || (yRoot < elLoc.y && xRoot == elLoc.x)) {
568-
sqCommon = (xRoot + widthRoot + elSize.width) + (yRoot + heightRoot + elSize.height);
569-
} else if ((elLoc.x < xRoot && yRoot == elLoc.y) || (elLoc.y < yRoot && xRoot == elLoc.x)) {
570-
sqCommon = (elLoc.x + elSize.width + widthRoot) * (elLoc.y + elSize.height + heightRoot);
571-
}
572-
573-
return sqCommon - sqElement >= sqRootElement;
574-
}
575-
576-
private boolean elementsAreOverlapped(WebElement elementOverlapWith) {
577-
Point elLoc = elementOverlapWith.getLocation();
578-
Dimension elSize = elementOverlapWith.getSize();
579-
return ((xRoot >= elLoc.x && yRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
580-
|| (xRoot + widthRoot > elLoc.x && yRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
581-
|| (xRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot + heightRoot < elLoc.y + elSize.height)
582-
|| (xRoot + widthRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot + widthRoot < elLoc.y + elSize.height))
583-
584-
|| ((elLoc.x > xRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot)
585-
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot)
586-
|| (elLoc.x > xRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot + heightRoot)
587-
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + widthRoot))
588-
589-
|| elementsAreOverlappedOnBorder(rootElement, elementOverlapWith);
590-
}
591-
592-
private boolean elementsAreOverlapped(WebElement rootElement, WebElement elementOverlapWith) {
593-
Point elLoc = elementOverlapWith.getLocation();
594-
Dimension elSize = elementOverlapWith.getSize();
595-
int xRoot = rootElement.getLocation().x;
596-
int yRoot = rootElement.getLocation().y;
597-
int widthRoot = rootElement.getSize().width;
598-
int heightRoot = rootElement.getSize().height;
599-
600-
return ((xRoot > elLoc.x && yRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
601-
|| (xRoot + widthRoot > elLoc.x && yRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
602-
|| (xRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot + heightRoot < elLoc.y + elSize.height)
603-
|| (xRoot + widthRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot + widthRoot < elLoc.y + elSize.height))
604-
605-
|| ((elLoc.x > xRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot)
606-
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot)
607-
|| (elLoc.x > xRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot + heightRoot)
608-
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + widthRoot))
609-
610-
|| elementsAreOverlappedOnBorder(rootElement, elementOverlapWith);
611-
}
612-
613-
private boolean elementsHaveEqualLeftRightOffset(boolean isLeft, WebElement elementToCompare) {
614-
Point elLoc = elementToCompare.getLocation();
615-
Dimension elSize = elementToCompare.getSize();
616-
617-
if (isLeft) {
618-
return xRoot == elLoc.getX();
619-
} else {
620-
return (pageWidth - xRoot + widthRoot) == (pageWidth - elLoc.getX() + elSize.getWidth());
621-
}
622-
}
623-
624-
private boolean elementsHaveEqualLeftRightOffset(boolean isLeft, WebElement element, WebElement elementToCompare) {
625-
Point elLoc = elementToCompare.getLocation();
626-
Dimension elSize = elementToCompare.getSize();
627-
int xRoot = element.getLocation().x;
628-
int widthRoot = element.getSize().width;
629-
630-
if (isLeft) {
631-
return xRoot == elLoc.getX();
632-
} else {
633-
return (pageWidth - xRoot + widthRoot) == (pageWidth - elLoc.getX() + elSize.getWidth());
634-
}
635-
}
636-
637-
638-
private boolean elementsHaveEqualTopBottomOffset(boolean isTop, WebElement elementToCompare) {
639-
Point elLoc = elementToCompare.getLocation();
640-
Dimension elSize = elementToCompare.getSize();
641-
642-
if (isTop) {
643-
return yRoot == elLoc.getY();
644-
} else {
645-
return (pageHeight - yRoot + heightRoot) == (pageHeight - elLoc.getY() + elSize.getHeight());
646-
}
647-
}
648-
649-
private boolean elementsHaveEqualTopBottomOffset(boolean isTop, WebElement element, WebElement elementToCompare) {
650-
Point elLoc = elementToCompare.getLocation();
651-
Dimension elSize = elementToCompare.getSize();
652-
int yRoot = element.getLocation().y;
653-
int heightRoot = element.getSize().height;
654-
655-
if (isTop) {
656-
return yRoot == elLoc.getY();
657-
} else {
658-
return (pageHeight - yRoot + heightRoot) == (pageHeight - elLoc.getY() + elSize.getHeight());
659-
}
660-
}
661-
662533
void validateEqualLeftRightOffset(WebElement element, String rootElementReadableName) {
663534
if (!elementHasEqualLeftRightOffset(element)) {
664535
putJsonDetailsWithElement(String.format("Element '%s' has not equal left and right offset. Left offset is %dpx, right is %dpx", rootElementReadableName, getLeftOffset(element), getRightOffset(element)), element);
@@ -687,14 +558,6 @@ void validateEqualTopBottomOffset(List<WebElement> elements) {
687558
}
688559
}
689560

690-
private boolean elementHasEqualLeftRightOffset(WebElement element) {
691-
return getLeftOffset(element) == getRightOffset(element);
692-
}
693-
694-
private boolean elementHasEqualTopBottomOffset(WebElement element) {
695-
return getTopOffset(element) == getBottomOffset(element);
696-
}
697-
698561
void drawRoot(Color color) {
699562
g.setColor(color);
700563
g.setStroke(new BasicStroke(2));
@@ -745,7 +608,7 @@ private void putJsonDetailsWithElement(String message, WebElement element) {
745608
errorMessage.add(details);
746609
}
747610

748-
int getInt(int i, boolean horizontal) {
611+
int getConvertedInt(int i, boolean horizontal) {
749612
if (units.equals(PX)) {
750613
return i;
751614
} else {
@@ -758,7 +621,7 @@ int getInt(int i, boolean horizontal) {
758621
}
759622

760623
String getFormattedMessage(WebElement element) {
761-
return String.format("with properties: tag='%s', id='%s', class='%s', text='%s', coord=[%s,%s], size=[%s,%s]",
624+
return String.format("with properties: tag=[%s], id=[%s], class=[%s], text=[%s], coord=[%s,%s], size=[%s,%s]",
762625
element.getTagName(),
763626
element.getAttribute("id"),
764627
element.getAttribute("class"),
@@ -777,40 +640,177 @@ int getRetinaValue(int value) {
777640
}
778641
}
779642

780-
int getLeftOffset(WebElement element) {
643+
long getPageWidth() {
644+
if (!isMobile()) {
645+
JavascriptExecutor executor = (JavascriptExecutor) driver;
646+
return (long) executor.executeScript("if (self.innerWidth) {return self.innerWidth;} if (document.documentElement && document.documentElement.clientWidth) {return document.documentElement.clientWidth;}if (document.body) {return document.body.clientWidth;}");
647+
} else {
648+
return driver.manage().window().getSize().width;
649+
}
650+
}
651+
652+
long getPageHeight() {
653+
if (!isMobile()) {
654+
JavascriptExecutor executor = (JavascriptExecutor) driver;
655+
return (long) executor.executeScript("if (self.innerHeight) {return self.innerHeight;} if (document.documentElement && document.documentElement.clientHeight) {return document.documentElement.clientHeight;}if (document.body) {return document.body.clientHeight;}");
656+
} else {
657+
return driver.manage().window().getSize().height;
658+
}
659+
}
660+
661+
private void validateInsideOfContainer(WebElement element, String readableContainerName) {
662+
float xContainer = element.getLocation().x;
663+
float yContainer = element.getLocation().y;
664+
float widthContainer = element.getSize().width;
665+
float heightContainer = element.getSize().height;
666+
if (rootElements == null || rootElements.isEmpty()) {
667+
if (xRoot < xContainer || yRoot < yContainer || (xRoot + widthRoot) > (xContainer + widthContainer) || (yRoot + heightRoot) > (yContainer + heightContainer)) {
668+
putJsonDetailsWithElement(String.format("Element '%s' is not inside of '%s'", rootElementReadableName, readableContainerName), element);
669+
}
670+
} else {
671+
for (WebElement el : rootElements) {
672+
float xRoot = el.getLocation().x;
673+
float yRoot = el.getLocation().y;
674+
float widthRoot = el.getSize().width;
675+
float heightRoot = el.getSize().height;
676+
if (xRoot < xContainer || yRoot < yContainer || (xRoot + widthRoot) > (xContainer + widthContainer) || (yRoot + heightRoot) > (yContainer + heightContainer)) {
677+
putJsonDetailsWithElement(String.format("Element is not inside of '%s'", readableContainerName), element);
678+
}
679+
}
680+
}
681+
}
682+
683+
private int getLeftOffset(WebElement element) {
781684
return element.getLocation().x;
782685
}
783686

784-
int getRightOffset(WebElement element) {
687+
private int getRightOffset(WebElement element) {
785688
return pageWidth - (element.getLocation().x + element.getSize().width);
786689
}
787690

788-
int getTopOffset(WebElement element) {
691+
private int getTopOffset(WebElement element) {
789692
return element.getLocation().y;
790693
}
791694

792-
int getBottomOffset(WebElement element) {
695+
private int getBottomOffset(WebElement element) {
793696
return pageHeight - (element.getLocation().y + element.getSize().height);
794697
}
795698

796-
long getPageWidth() {
797-
if (!isMobile()) {
798-
JavascriptExecutor executor = (JavascriptExecutor) driver;
799-
return (long) executor.executeScript("if (self.innerWidth) {return self.innerWidth;} if (document.documentElement && document.documentElement.clientWidth) {return document.documentElement.clientWidth;}if (document.body) {return document.body.clientWidth;}");
699+
private boolean elementsAreOverlappedOnBorder(WebElement rootElement, WebElement elementOverlapWith) {
700+
Point elLoc = elementOverlapWith.getLocation();
701+
Dimension elSize = elementOverlapWith.getSize();
702+
int xRoot = rootElement.getLocation().x;
703+
int yRoot = rootElement.getLocation().y;
704+
int widthRoot = rootElement.getSize().width;
705+
int heightRoot = rootElement.getSize().height;
706+
707+
int sqRootElement = (xRoot + widthRoot) * (yRoot + heightRoot);
708+
int sqElement = (elLoc.x + elSize.width) * (elLoc.y + elSize.height);
709+
710+
int sqCommon = 0;
711+
if ((xRoot < elLoc.x && yRoot == elLoc.y) || (yRoot < elLoc.y && xRoot == elLoc.x)) {
712+
sqCommon = (xRoot + widthRoot + elSize.width) + (yRoot + heightRoot + elSize.height);
713+
} else if ((elLoc.x < xRoot && yRoot == elLoc.y) || (elLoc.y < yRoot && xRoot == elLoc.x)) {
714+
sqCommon = (elLoc.x + elSize.width + widthRoot) * (elLoc.y + elSize.height + heightRoot);
715+
}
716+
717+
return sqCommon - sqElement >= sqRootElement;
718+
}
719+
720+
private boolean elementsAreOverlapped(WebElement elementOverlapWith) {
721+
Point elLoc = elementOverlapWith.getLocation();
722+
Dimension elSize = elementOverlapWith.getSize();
723+
return ((xRoot >= elLoc.x && yRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
724+
|| (xRoot + widthRoot > elLoc.x && yRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
725+
|| (xRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot + heightRoot < elLoc.y + elSize.height)
726+
|| (xRoot + widthRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot + widthRoot < elLoc.y + elSize.height))
727+
728+
|| ((elLoc.x > xRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot)
729+
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot)
730+
|| (elLoc.x > xRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot + heightRoot)
731+
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + widthRoot))
732+
733+
|| elementsAreOverlappedOnBorder(rootElement, elementOverlapWith);
734+
}
735+
736+
private boolean elementsAreOverlapped(WebElement rootElement, WebElement elementOverlapWith) {
737+
Point elLoc = elementOverlapWith.getLocation();
738+
Dimension elSize = elementOverlapWith.getSize();
739+
int xRoot = rootElement.getLocation().x;
740+
int yRoot = rootElement.getLocation().y;
741+
int widthRoot = rootElement.getSize().width;
742+
int heightRoot = rootElement.getSize().height;
743+
744+
return ((xRoot > elLoc.x && yRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
745+
|| (xRoot + widthRoot > elLoc.x && yRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
746+
|| (xRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot + heightRoot < elLoc.y + elSize.height)
747+
|| (xRoot + widthRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot + widthRoot < elLoc.y + elSize.height))
748+
749+
|| ((elLoc.x > xRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot)
750+
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot)
751+
|| (elLoc.x > xRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot + heightRoot)
752+
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + widthRoot))
753+
754+
|| elementsAreOverlappedOnBorder(rootElement, elementOverlapWith);
755+
}
756+
757+
private boolean elementsHaveEqualLeftRightOffset(boolean isLeft, WebElement elementToCompare) {
758+
Point elLoc = elementToCompare.getLocation();
759+
Dimension elSize = elementToCompare.getSize();
760+
761+
if (isLeft) {
762+
return xRoot == elLoc.getX();
800763
} else {
801-
return driver.manage().window().getSize().width;
764+
return (pageWidth - xRoot + widthRoot) == (pageWidth - elLoc.getX() + elSize.getWidth());
802765
}
803766
}
804767

805-
long getPageHeight() {
806-
if (!isMobile()) {
807-
JavascriptExecutor executor = (JavascriptExecutor) driver;
808-
return (long) executor.executeScript("if (self.innerHeight) {return self.innerHeight;} if (document.documentElement && document.documentElement.clientHeight) {return document.documentElement.clientHeight;}if (document.body) {return document.body.clientHeight;}");
768+
private boolean elementsHaveEqualLeftRightOffset(boolean isLeft, WebElement element, WebElement elementToCompare) {
769+
Point elLoc = elementToCompare.getLocation();
770+
Dimension elSize = elementToCompare.getSize();
771+
int xRoot = element.getLocation().x;
772+
int widthRoot = element.getSize().width;
773+
774+
if (isLeft) {
775+
return xRoot == elLoc.getX();
809776
} else {
810-
return driver.manage().window().getSize().height;
777+
return (pageWidth - xRoot + widthRoot) == (pageWidth - elLoc.getX() + elSize.getWidth());
778+
}
779+
}
780+
781+
782+
private boolean elementsHaveEqualTopBottomOffset(boolean isTop, WebElement elementToCompare) {
783+
Point elLoc = elementToCompare.getLocation();
784+
Dimension elSize = elementToCompare.getSize();
785+
786+
if (isTop) {
787+
return yRoot == elLoc.getY();
788+
} else {
789+
return (pageHeight - yRoot + heightRoot) == (pageHeight - elLoc.getY() + elSize.getHeight());
790+
}
791+
}
792+
793+
private boolean elementsHaveEqualTopBottomOffset(boolean isTop, WebElement element, WebElement elementToCompare) {
794+
Point elLoc = elementToCompare.getLocation();
795+
Dimension elSize = elementToCompare.getSize();
796+
int yRoot = element.getLocation().y;
797+
int heightRoot = element.getSize().height;
798+
799+
if (isTop) {
800+
return yRoot == elLoc.getY();
801+
} else {
802+
return (pageHeight - yRoot + heightRoot) == (pageHeight - elLoc.getY() + elSize.getHeight());
811803
}
812804
}
813805

806+
private boolean elementHasEqualLeftRightOffset(WebElement element) {
807+
return getLeftOffset(element) == getRightOffset(element);
808+
}
809+
810+
private boolean elementHasEqualTopBottomOffset(WebElement element) {
811+
return getTopOffset(element) == getBottomOffset(element);
812+
}
813+
814814
public enum Units {
815815
PX,
816816
PERCENT

0 commit comments

Comments
 (0)