Skip to content

Commit 764d9ec

Browse files
author
Denys Zaiats
committed
[issue-24] - init fix
1 parent 693203c commit 764d9ec

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ private static DesiredCapabilities getPhantomJSCapabilities() {
8585
capabilities.setCapability("browserName", "PhantomJS");
8686
capabilities.setCapability("browser", "phantomjs");
8787
capabilities.setCapability("phantomjs.page.settings.userAgent", getUserAgent());
88+
capabilities.setCapability("acceptSslCerts", true);
89+
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--web-security=no", "--ignore-ssl-errors=yes","--ignore-ssl-errors=true","--ssl-protocol=tlsv1"});
8890
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
8991
getPhantomJsPath()
9092
);

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

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public class ResponsiveUIValidator {
3535
protected static WebDriver driver;
3636
static WebElement rootElement;
3737
static long startTime;
38+
static boolean drawLeftOffsetLine = false;
39+
static boolean drawRightOffsetLine = false;
40+
static boolean drawTopOffsetLine = false;
41+
static boolean drawBottomOffsetLine = false;
42+
static boolean isMobileTopBar = false;
3843
private static boolean withReport = false;
3944
private static String scenarioName = "Default";
4045
private static Color rootColor = new Color(255, 0, 0, 255);
@@ -47,10 +52,6 @@ public class ResponsiveUIValidator {
4752
private static JSONArray errorMessage;
4853
String rootElementReadableName = "Root Element";
4954
List<WebElement> rootElements;
50-
boolean drawLeftOffsetLine = false;
51-
boolean drawRightOffsetLine = false;
52-
boolean drawTopOffsetLine = false;
53-
boolean drawBottomOffsetLine = false;
5455
ResponsiveUIValidator.Units units = PX;
5556
int xRoot;
5657
int yRoot;
@@ -91,6 +92,15 @@ public void setLinesColor(Color color) {
9192
linesColor = color;
9293
}
9394

95+
/**
96+
* Set top bar mobile offset. Applicable only for native mobile testing
97+
*
98+
* @param state
99+
*/
100+
public void setTopBarMobileOffset(boolean state) {
101+
isMobileTopBar = state;
102+
}
103+
94104
/**
95105
* Method that defines start of new validation. Needs to be called each time before calling findElement(), findElements()
96106
*
@@ -267,7 +277,7 @@ void drawScreenshot() {
267277

268278
g.setColor(highlightedElementsColor);
269279
g.setStroke(new BasicStroke(2));
270-
g.drawRect(getRetinaValue((int) x), getRetinaValue((int) y), getRetinaValue((int) width), getRetinaValue((int) height));
280+
g.drawRect(retinaValue((int) x), retinaValue(mobileY((int) y)), retinaValue((int) width), retinaValue((int) height));
271281
}
272282
}
273283

@@ -624,23 +634,23 @@ void validateEqualTopBottomOffset(List<WebElement> elements) {
624634
void drawRoot(Color color) {
625635
g.setColor(color);
626636
g.setStroke(new BasicStroke(2));
627-
g.drawRect(getRetinaValue(xRoot), getRetinaValue(yRoot), getRetinaValue(widthRoot), getRetinaValue(heightRoot));
628-
//g.fillRect(getRetinaValue(xRoot), getRetinaValue((yRoot), getRetinaValue(widthRoot), getRetinaValue(heightRoot));
637+
g.drawRect(retinaValue(xRoot), retinaValue(mobileY(yRoot)), retinaValue(widthRoot), retinaValue(heightRoot));
638+
//g.fillRect(retinaValue(xRoot), retinaValue((yRoot), retinaValue(widthRoot), retinaValue(heightRoot));
629639

630640
Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{9}, 0);
631641
g.setStroke(dashed);
632642
g.setColor(linesColor);
633643
if (drawLeftOffsetLine) {
634-
g.drawLine(getRetinaValue(xRoot), 0, getRetinaValue(xRoot), getRetinaValue(img.getHeight()));
644+
g.drawLine(retinaValue(xRoot), 0, retinaValue(xRoot), retinaValue(img.getHeight()));
635645
}
636646
if (drawRightOffsetLine) {
637-
g.drawLine(getRetinaValue(xRoot + widthRoot), 0, getRetinaValue(xRoot + widthRoot), getRetinaValue(img.getHeight()));
647+
g.drawLine(retinaValue(xRoot + widthRoot), 0, retinaValue(xRoot + widthRoot), retinaValue(img.getHeight()));
638648
}
639649
if (drawTopOffsetLine) {
640-
g.drawLine(0, getRetinaValue(yRoot), getRetinaValue(img.getWidth()), getRetinaValue(yRoot));
650+
g.drawLine(0, retinaValue(mobileY(yRoot)), retinaValue(img.getWidth()), retinaValue(yRoot));
641651
}
642652
if (drawBottomOffsetLine) {
643-
g.drawLine(0, getRetinaValue(yRoot + heightRoot), getRetinaValue(img.getWidth()), getRetinaValue(yRoot + heightRoot));
653+
g.drawLine(0, retinaValue(mobileY(yRoot + heightRoot)), retinaValue(img.getWidth()), retinaValue(yRoot + heightRoot));
644654
}
645655
}
646656

@@ -695,9 +705,9 @@ String getFormattedMessage(WebElement element) {
695705
String.valueOf(element.getSize().height));
696706
}
697707

698-
int getRetinaValue(int value) {
708+
int retinaValue(int value) {
699709
if (!isMobile()) {
700-
int zoom = Integer.valueOf(currentZoom.replace("%", ""));
710+
int zoom = Integer.parseInt(currentZoom.replace("%", ""));
701711
if (zoom > 100) {
702712
value = (int) (value + (value * Math.abs(zoom - 100f) / 100f));
703713
} else if (zoom < 100) {
@@ -717,6 +727,28 @@ int getRetinaValue(int value) {
717727
}
718728
}
719729

730+
int mobileY(int value) {
731+
if (isMobile()) {
732+
if (isIOS()) {
733+
if (isMobileTopBar) {
734+
return value + 20;
735+
} else {
736+
return value;
737+
}
738+
} else if (isAndroid()) {
739+
if (isMobileTopBar) {
740+
return value + 20;
741+
} else {
742+
return value;
743+
}
744+
} else {
745+
return value;
746+
}
747+
} else {
748+
return value;
749+
}
750+
}
751+
720752
long getPageWidth() {
721753
if (!isMobile()) {
722754
JavascriptExecutor executor = (JavascriptExecutor) driver;
@@ -831,7 +863,7 @@ private boolean elementsAreOverlapped(WebElement elementOverlapWith) {
831863
|| ((elLoc.x > xRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot)
832864
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot)
833865
|| (elLoc.x > xRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot + heightRoot)
834-
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + widthRoot))
866+
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + heightRoot))
835867

836868
|| elementsAreOverlappedOnBorder(rootElement, elementOverlapWith);
837869
}
@@ -852,7 +884,7 @@ private boolean elementsAreOverlapped(WebElement rootElement, WebElement element
852884
|| ((elLoc.x > xRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot)
853885
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot)
854886
|| (elLoc.x > xRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot + heightRoot)
855-
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + widthRoot))
887+
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + heightRoot))
856888

857889
|| elementsAreOverlappedOnBorder(rootElement, elementOverlapWith);
858890
}

0 commit comments

Comments
 (0)