Skip to content

Commit f4793fb

Browse files
committed
[1.4.2-fix-overlapping] - fix for validation overlapping
1 parent 1ebd329 commit f4793fb

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

src/main/java/environment/EnvironmentConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class EnvironmentConstants {
1111
public static final String EXECUTOR = "EXECUTOR";
1212
public static final String PLATFORM_VERSION = "PLATFORM_VERSION";
1313
public static final String PHANTOM_JS_PATH = "PHANTOM_JS_PATH";
14+
public static final String USER_AGENT = "USER_AGENT";
1415
public static final String DEVICE = "DEVICE";
1516
public static final String MOBILE_DEVICE_EMULATION = "MOBILE_DEVICE_EMULATION";
1617
public static final String NAME = "NAME";

src/main/java/environment/EnvironmentFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public static String getPhantomJsPath() {
8181
return System.getenv(EnvironmentConstants.PHANTOM_JS_PATH) != null ? System.getenv(EnvironmentConstants.PHANTOM_JS_PATH) : System.getProperty(EnvironmentConstants.PHANTOM_JS_PATH);
8282
}
8383

84+
public static String getUserAgent() {
85+
return System.getenv(EnvironmentConstants.USER_AGENT) != null ? System.getenv(EnvironmentConstants.USER_AGENT) : System.getProperty(EnvironmentConstants.USER_AGENT);
86+
}
87+
8488
public static String getDevice() {
8589
return System.getenv(EnvironmentConstants.DEVICE) != null ? System.getenv(EnvironmentConstants.DEVICE) : System.getProperty(EnvironmentConstants.DEVICE);
8690
}

src/main/java/util/driver/CapabilitiesFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ private static DesiredCapabilities getPhantomJSCapabilities() {
8383
capabilities.setJavascriptEnabled(true);
8484
capabilities.setCapability("takesScreenshot", true);
8585
capabilities.setCapability("browserName", "PhantomJS");
86-
capabilities.setCapability("browser", getBrowserName().toLowerCase());
86+
capabilities.setCapability("browser", "phantomjs");
87+
capabilities.setCapability("phantomjs.page.settings.userAgent", getUserAgent());
8788
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
8889
getPhantomJsPath()
8990
);

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -797,17 +797,23 @@ private boolean elementsAreOverlappedOnBorder(WebElement rootElement, WebElement
797797
int widthRoot = rootElement.getSize().width;
798798
int heightRoot = rootElement.getSize().height;
799799

800-
int sqRootElement = (xRoot + widthRoot) * (yRoot + heightRoot);
801-
int sqElement = (elLoc.x + elSize.width) * (elLoc.y + elSize.height);
800+
int sqRootElement = widthRoot * heightRoot;
801+
int sqElement = elSize.width * elSize.height;
802802

803803
int sqCommon = 0;
804-
if ((xRoot < elLoc.x && yRoot == elLoc.y) || (yRoot < elLoc.y && xRoot == elLoc.x)) {
805-
sqCommon = (xRoot + widthRoot + elSize.width) * (yRoot + heightRoot + elSize.height);
806-
} else if ((elLoc.x < xRoot && yRoot == elLoc.y) || (elLoc.y < yRoot && xRoot == elLoc.x)) {
807-
sqCommon = (elLoc.x + elSize.width + widthRoot) * (elLoc.y + elSize.height + heightRoot);
804+
if (xRoot < elLoc.x && yRoot == elLoc.y) {
805+
sqCommon = (widthRoot + (elLoc.x - (xRoot + widthRoot) + elSize.width)) * (heightRoot);
806+
} else if (yRoot < elLoc.y && xRoot == elLoc.x) {
807+
sqCommon = (heightRoot + (elLoc.y - (yRoot + heightRoot) + elSize.height)) * (widthRoot);
808+
} else if ((elLoc.x < xRoot && yRoot == elLoc.y)) {
809+
sqCommon = ((elSize.width) + (xRoot - (elLoc.x + elSize.width) + widthRoot)) * (elSize.height);
810+
} else if (elLoc.y < yRoot && xRoot == elLoc.x) {
811+
sqCommon = ((elSize.height) + (yRoot - (elLoc.y + elSize.height) + heightRoot)) * (elSize.width);
812+
} else {
813+
return false;
808814
}
809815

810-
return sqCommon - sqElement >= sqRootElement;
816+
return sqCommon < sqRootElement + sqElement;
811817
}
812818

813819
private boolean elementsAreOverlapped(WebElement elementOverlapWith) {

src/test/java/ResponsiveValidatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public void testThatResponsiveValidatorWorks() {
2525
Map<String, String> sysProp = new HashMap<>();
2626
//sysProp.put("BROWSER", "phantomjs");
2727
//sysProp.put("IS_HEADLESS", "true");
28-
sysProp.put("IS_LOCAL", "true");
29-
sysProp.put("BROWSER", "Firefox");
28+
sysProp.put("IS_HEADLESS", "true");
29+
sysProp.put("BROWSER", "phantomjs");
3030
sysProp.put(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "/Users/ZayCo/Downloads/phantomjs-2.1.1-macosx/bin/phantomjs");
3131
EnvironmentHelper.setEnv(sysProp);
3232
WebDriverFactory driverFactory = new WebDriverFactory();

0 commit comments

Comments
 (0)