2222import java .util .concurrent .ConcurrentHashMap ;
2323import java .util .concurrent .atomic .AtomicLong ;
2424
25- import static environment .EnvironmentFactory .isChrome ;
26- import static environment .EnvironmentFactory .isMobile ;
25+ import static environment .EnvironmentFactory .*;
2726import static util .general .SystemHelper .isAutomotionFolderExists ;
2827import static util .general .SystemHelper .isRetinaDisplay ;
2928import static util .validator .Constants .*;
@@ -41,6 +40,7 @@ public class ResponsiveUIValidator {
4140 private static Color rootColor = new Color (255 , 0 , 0 , 255 );
4241 private static Color highlightedElementsColor = new Color (255 , 0 , 255 , 255 );
4342 private static Color linesColor = Color .ORANGE ;
43+ private static String currentZoom = "100%" ;
4444 private static File screenshot ;
4545 private static BufferedImage img ;
4646 private static Graphics2D g ;
@@ -697,8 +697,16 @@ String getFormattedMessage(WebElement element) {
697697 }
698698
699699 int getRetinaValue (int value ) {
700- if (isRetinaDisplay () && isChrome ()) {
701- return 2 * value ;
700+ if (!isMobile ()) {
701+ int zoom = Integer .valueOf (currentZoom .replace ("%" , "" ));
702+ if (zoom != 100 ) {
703+ value = (int ) (value - (value * Math .abs (zoom - 100f ) / 100f ));
704+ }
705+ if (isRetinaDisplay () && isChrome ()) {
706+ return 2 * value ;
707+ } else {
708+ return value ;
709+ }
702710 } else {
703711 return value ;
704712 }
@@ -707,7 +715,17 @@ int getRetinaValue(int value) {
707715 long getPageWidth () {
708716 if (!isMobile ()) {
709717 JavascriptExecutor executor = (JavascriptExecutor ) driver ;
710- 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;}" );
718+ if (isFirefox ()) {
719+ currentZoom = (String ) executor .executeScript ("document.body.style.MozTransform" );
720+ } else {
721+ currentZoom = (String ) executor .executeScript ("return document.body.style.zoom;" );
722+ }
723+ if (currentZoom == null || currentZoom .equals ("100%" ) || currentZoom .equals ("" )) {
724+ currentZoom = "100%" ;
725+ 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;}" );
726+ } else {
727+ return (long ) executor .executeScript ("return document.getElementsByTagName('body')[0].offsetWidth" );
728+ }
711729 } else {
712730 return driver .manage ().window ().getSize ().width ;
713731 }
@@ -716,7 +734,17 @@ long getPageWidth() {
716734 long getPageHeight () {
717735 if (!isMobile ()) {
718736 JavascriptExecutor executor = (JavascriptExecutor ) driver ;
719- 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;}" );
737+ if (isFirefox ()) {
738+ currentZoom = (String ) executor .executeScript ("document.body.style.MozTransform" );
739+ } else {
740+ currentZoom = (String ) executor .executeScript ("return document.body.style.zoom;" );
741+ }
742+ if (currentZoom == null || currentZoom .equals ("100%" ) || currentZoom .equals ("" )) {
743+ currentZoom = "100%" ;
744+ 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;}" );
745+ } else {
746+ return (long ) executor .executeScript ("return document.getElementsByTagName('body')[0].offsetHeight" );
747+ }
720748 } else {
721749 return driver .manage ().window ().getSize ().height ;
722750 }
0 commit comments