@@ -84,6 +84,7 @@ public ResponsiveUIValidator findElements(List<WebElement> elements) {
8484 rootElements = elements ;
8585 pageWidth = driver .manage ().window ().getSize ().getWidth ();
8686 pageHeight = driver .manage ().window ().getSize ().getHeight ();
87+ rootElement = rootElements .get (0 );
8788 return this ;
8889 }
8990
@@ -375,6 +376,13 @@ public ResponsiveUIValidator alignedAsGrid(int horizontalGridSize, int verticalG
375376 return this ;
376377 }
377378
379+ @ Override
380+ public ResponsiveUIValidator areNotOverlappedWithEachOther () {
381+ validateElementsAreNotOverlapped (rootElements );
382+ return this ;
383+ }
384+
385+
378386 @ Override
379387 public ResponsiveUIValidator drawMap () {
380388 withReport = true ;
@@ -453,6 +461,15 @@ public void generateReport() {
453461 }
454462 }
455463
464+ @ Override
465+ public void generateReport (String name ) {
466+ try {
467+ new HtmlReportBuilder ().buildReport (name );
468+ } catch (IOException | ParseException | InterruptedException e ) {
469+ e .printStackTrace ();
470+ }
471+ }
472+
456473 private void drawScreenshot () {
457474 g = img .createGraphics ();
458475
@@ -488,6 +505,19 @@ private void drawScreenshot() {
488505 }
489506 }
490507
508+ private void validateElementsAreNotOverlapped (List <WebElement > rootElements ) {
509+ for (WebElement el1 : rootElements ) {
510+ for (WebElement el2 : rootElements ) {
511+ if (!el1 .equals (el2 )) {
512+ if (elementsAreOverlapped (el1 , el2 )) {
513+ putJsonDetailsWithElement ("Elements are overlapped" , el1 );
514+ break ;
515+ }
516+ }
517+ }
518+ }
519+ }
520+
491521 private void validateGridAlignment (int horizontalGridSize , int verticalGridSize ) {
492522 List <WebElement > row = new ArrayList <>();
493523 for (int i = 0 ; i < rootElements .size (); i ++) {
@@ -730,10 +760,32 @@ private void validateLeftElement(WebElement leftElement) {
730760 private boolean elementsAreOverlapped (WebElement elementOverlapWith ) {
731761 Point elLoc = elementOverlapWith .getLocation ();
732762 Dimension elSize = elementOverlapWith .getSize ();
733- return (xRoot > elLoc .x && yRoot > elLoc .y && xRoot < elLoc .x + elSize .width && yRoot < elLoc .y + elSize .height )
763+ return ((xRoot > elLoc .x && yRoot > elLoc .y && xRoot < elLoc .x + elSize .width && yRoot < elLoc .y + elSize .height )
764+ || (xRoot + widthRoot > elLoc .x && yRoot > elLoc .y && xRoot + widthRoot < elLoc .x + elSize .width && yRoot < elLoc .y + elSize .height )
765+ || (xRoot > elLoc .x && yRoot + heightRoot > elLoc .y && xRoot < elLoc .x + elSize .width && yRoot + heightRoot < elLoc .y + elSize .height )
766+ || (xRoot + widthRoot > elLoc .x && yRoot + heightRoot > elLoc .y && xRoot + widthRoot < elLoc .x + elSize .width && yRoot + widthRoot < elLoc .y + elSize .height )) ||
767+ ((elLoc .x > xRoot && elLoc .y > yRoot && elLoc .x + elSize .width < xRoot && elLoc .y + elSize .height < yRoot )
768+ || (elLoc .x > xRoot + widthRoot && elLoc .y > yRoot && elLoc .x + elSize .width < xRoot + widthRoot && elLoc .y + elSize .height < yRoot )
769+ || (elLoc .x > xRoot && elLoc .y > yRoot + heightRoot && elLoc .x + elSize .width < xRoot && elLoc .y + elSize .height < yRoot + heightRoot )
770+ || (elLoc .x > xRoot + widthRoot && elLoc .y > yRoot + heightRoot && elLoc .x + elSize .width < xRoot + widthRoot && elLoc .y + elSize .height < yRoot + widthRoot ));
771+ }
772+
773+ private boolean elementsAreOverlapped (WebElement rootElement , WebElement elementOverlapWith ) {
774+ Point elLoc = elementOverlapWith .getLocation ();
775+ Dimension elSize = elementOverlapWith .getSize ();
776+ int xRoot = rootElement .getLocation ().x ;
777+ int yRoot = rootElement .getLocation ().y ;
778+ int widthRoot = rootElement .getSize ().width ;
779+ int heightRoot = rootElement .getSize ().height ;
780+
781+ return ((xRoot > elLoc .x && yRoot > elLoc .y && xRoot < elLoc .x + elSize .width && yRoot < elLoc .y + elSize .height )
734782 || (xRoot + widthRoot > elLoc .x && yRoot > elLoc .y && xRoot + widthRoot < elLoc .x + elSize .width && yRoot < elLoc .y + elSize .height )
735783 || (xRoot > elLoc .x && yRoot + heightRoot > elLoc .y && xRoot < elLoc .x + elSize .width && yRoot + heightRoot < elLoc .y + elSize .height )
736- || (xRoot + widthRoot > elLoc .x && yRoot + heightRoot > elLoc .y && xRoot + widthRoot < elLoc .x + elSize .width && yRoot + widthRoot < elLoc .y + elSize .height );
784+ || (xRoot + widthRoot > elLoc .x && yRoot + heightRoot > elLoc .y && xRoot + widthRoot < elLoc .x + elSize .width && yRoot + widthRoot < elLoc .y + elSize .height )) ||
785+ ((elLoc .x > xRoot && elLoc .y > yRoot && elLoc .x + elSize .width < xRoot && elLoc .y + elSize .height < yRoot )
786+ || (elLoc .x > xRoot + widthRoot && elLoc .y > yRoot && elLoc .x + elSize .width < xRoot + widthRoot && elLoc .y + elSize .height < yRoot )
787+ || (elLoc .x > xRoot && elLoc .y > yRoot + heightRoot && elLoc .x + elSize .width < xRoot && elLoc .y + elSize .height < yRoot + heightRoot )
788+ || (elLoc .x > xRoot + widthRoot && elLoc .y > yRoot + heightRoot && elLoc .x + elSize .width < xRoot + widthRoot && elLoc .y + elSize .height < yRoot + widthRoot ));
737789 }
738790
739791 private boolean elementsHasEqualLeftRightOffset (boolean isLeft , WebElement elementToCompare ) {
0 commit comments