@@ -84,6 +84,7 @@ public ResponsiveUIValidator findElements(List<WebElement> elements) {
84
84
rootElements = elements ;
85
85
pageWidth = driver .manage ().window ().getSize ().getWidth ();
86
86
pageHeight = driver .manage ().window ().getSize ().getHeight ();
87
+ rootElement = rootElements .get (0 );
87
88
return this ;
88
89
}
89
90
@@ -375,6 +376,13 @@ public ResponsiveUIValidator alignedAsGrid(int horizontalGridSize, int verticalG
375
376
return this ;
376
377
}
377
378
379
+ @ Override
380
+ public ResponsiveUIValidator areNotOverlappedWithEachOther () {
381
+ validateElementsAreNotOverlapped (rootElements );
382
+ return this ;
383
+ }
384
+
385
+
378
386
@ Override
379
387
public ResponsiveUIValidator drawMap () {
380
388
withReport = true ;
@@ -453,6 +461,15 @@ public void generateReport() {
453
461
}
454
462
}
455
463
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
+
456
473
private void drawScreenshot () {
457
474
g = img .createGraphics ();
458
475
@@ -488,6 +505,19 @@ private void drawScreenshot() {
488
505
}
489
506
}
490
507
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
+
491
521
private void validateGridAlignment (int horizontalGridSize , int verticalGridSize ) {
492
522
List <WebElement > row = new ArrayList <>();
493
523
for (int i = 0 ; i < rootElements .size (); i ++) {
@@ -730,10 +760,32 @@ private void validateLeftElement(WebElement leftElement) {
730
760
private boolean elementsAreOverlapped (WebElement elementOverlapWith ) {
731
761
Point elLoc = elementOverlapWith .getLocation ();
732
762
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 )
734
782
|| (xRoot + widthRoot > elLoc .x && yRoot > elLoc .y && xRoot + widthRoot < elLoc .x + elSize .width && yRoot < elLoc .y + elSize .height )
735
783
|| (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 ));
737
789
}
738
790
739
791
private boolean elementsHasEqualLeftRightOffset (boolean isLeft , WebElement elementToCompare ) {
0 commit comments