Skip to content

Commit ed45401

Browse files
authored
Merge pull request #81 from ITArray/update_dependencies
Update dependencies. Added the fixes for mobile.
2 parents bbf5cc9 + b8e87b1 commit ed45401

File tree

7 files changed

+87
-44
lines changed

7 files changed

+87
-44
lines changed

pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>net.itarray</groupId>
88
<artifactId>automotion</artifactId>
9-
<version>2.0.4</version>
9+
<version>2.0.5</version>
1010
<name>Automotion</name>
1111
<description>Library for smart visual automation testing</description>
1212
<url>https://automotion.itarray.net</url>
@@ -121,27 +121,27 @@
121121
<dependency>
122122
<groupId>org.seleniumhq.selenium</groupId>
123123
<artifactId>selenium-java</artifactId>
124-
<version>3.5.3</version>
124+
<version>3.7.1</version>
125125
</dependency>
126126
<dependency>
127127
<groupId>org.seleniumhq.selenium</groupId>
128128
<artifactId>selenium-server</artifactId>
129-
<version>3.5.3</version>
129+
<version>3.7.1</version>
130130
</dependency>
131131
<dependency>
132132
<groupId>org.seleniumhq.selenium</groupId>
133133
<artifactId>selenium-remote-driver</artifactId>
134-
<version>3.5.3</version>
134+
<version>3.7.1</version>
135135
</dependency>
136136
<dependency>
137137
<groupId>io.appium</groupId>
138138
<artifactId>java-client</artifactId>
139-
<version>5.0.2</version>
139+
<version>5.0.4</version>
140140
</dependency>
141141
<dependency>
142142
<groupId>com.google.guava</groupId>
143143
<artifactId>guava</artifactId>
144-
<version>23.0</version>
144+
<version>23.5-jre</version>
145145
</dependency>
146146
<dependency>
147147
<groupId>org.apache.httpcomponents</groupId>
@@ -200,7 +200,7 @@
200200
<dependency>
201201
<groupId>com.webfirmframework</groupId>
202202
<artifactId>wffweb</artifactId>
203-
<version>2.1.12</version>
203+
<version>2.1.13</version>
204204
</dependency>
205205
<dependency>
206206
<groupId>org.assertj</groupId>

src/main/java/net/itarray/automotion/internal/DriverFacade.java

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.itarray.automotion.internal;
22

33
import io.appium.java_client.AppiumDriver;
4+
import io.appium.java_client.android.AndroidDriver;
45
import org.openqa.selenium.*;
56
import org.openqa.selenium.remote.RemoteWebDriver;
67

@@ -33,6 +34,31 @@ public void takeScreenshot(File file) {
3334
}
3435
}
3536

37+
public WebDriver getDriver() {
38+
return driver;
39+
}
40+
41+
public boolean isAppiumAndroidContext() {
42+
if ((driver instanceof AndroidDriver)) {
43+
return true;
44+
}
45+
return false;
46+
}
47+
48+
public boolean isAppiumIOSContext() {
49+
if ((driver instanceof AndroidDriver)) {
50+
return true;
51+
}
52+
return false;
53+
}
54+
55+
public boolean isAppiumContext() {
56+
if ((driver instanceof AppiumDriver)) {
57+
return true;
58+
}
59+
return false;
60+
}
61+
3662
public boolean isAppiumWebContext() {
3763
if (!(driver instanceof AppiumDriver)) {
3864
return false;
@@ -52,11 +78,15 @@ public Object executeScript(String script) {
5278
}
5379

5480
public String getZoom() {
55-
String zoom = (String) executeScript(getZoomScript());
56-
if (zoom == null || zoom.equals("")) {
57-
zoom = "100%";
81+
if (!isAppiumContext()) {
82+
String zoom = (String) executeScript(getZoomScript());
83+
if (zoom == null || zoom.equals("")) {
84+
zoom = "100%";
85+
}
86+
return zoom;
87+
} else {
88+
return "100%";
5889
}
59-
return zoom;
6090
}
6191

6292
private String getZoomScript() {
@@ -68,34 +98,34 @@ private String getZoomScript() {
6898
}
6999

70100
private long retrievePageHeight() {
71-
if (!isMobile()) {
101+
if (!isAppiumAndroidContext()) {
72102
if (getZoom().equals("100%")) {
73-
return (long) executeScript("if (self.innerHeight) {return self.innerHeight;} if (document.documentElement && document.documentElement.clientHeight) {return document.documentElement.clientHeight;}if (document.body) {return document.body.clientHeight;}");
103+
return (long) executeScript("if (self.outerHeight) {return self.outerHeight;} if (document.documentElement && document.documentElement.clientHeight) {return document.documentElement.clientHeight;}if (document.body) {return document.body.clientHeight;}");
74104
} else {
75105
return (long) executeScript("return document.getElementsByTagName('body')[0].offsetHeight");
76106
}
77107
} else {
78-
if (isAppiumNativeMobileContext() || isIOS()) {
108+
if (isAppiumNativeMobileContext() || isAppiumIOSContext()) {
79109
return driver.manage().window().getSize().getHeight();
80110
} else {
81-
return (long) executeScript("if (self.innerHeight) {return self.innerHeight;} if (document.documentElement && document.documentElement.clientHeight) {return document.documentElement.clientHeight;}if (document.body) {return document.body.clientHeight;}");
111+
return (long) executeScript("if (self.outerHeight) {return self.outerHeight;} if (document.documentElement && document.documentElement.clientHeight) {return document.documentElement.clientHeight;}if (document.body) {return document.body.clientHeight;}");
82112
}
83113
}
84114
}
85115

86116
private long retrievePageWidth() {
87-
if (!isMobile()) {
117+
if (!isAppiumAndroidContext()) {
88118
if (getZoom().equals("100%")) {
89-
String script = "if (self.innerWidth) {return self.innerWidth;} if (document.documentElement && document.documentElement.clientWidth) {return document.documentElement.clientWidth;}if (document.body) {return document.body.clientWidth;}";
119+
String script = "if (self.outerWidth) {return self.outerWidth;} if (document.documentElement && document.documentElement.clientWidth) {return document.documentElement.clientWidth;}if (document.body) {return document.body.clientWidth;}";
90120
return (long) executeScript(script);
91121
} else {
92122
return (long) executeScript("return document.getElementsByTagName('body')[0].offsetWidth");
93123
}
94124
} else {
95-
if (isAppiumNativeMobileContext() || isIOS()) {
125+
if (isAppiumNativeMobileContext() || isAppiumIOSContext()) {
96126
return driver.manage().window().getSize().getWidth();
97127
} else {
98-
return (long) executeScript("if (self.innerWidth) {return self.innerWidth;} if (document.documentElement && document.documentElement.clientWidth) {return document.documentElement.clientWidth;}if (document.body) {return document.body.clientWidth;}");
128+
return (long) executeScript("if (self.outerWidth) {return self.outerWidth;} if (document.documentElement && document.documentElement.clientWidth) {return document.documentElement.clientWidth;}if (document.body) {return document.body.clientWidth;}");
99129
}
100130
}
101131
}
@@ -110,7 +140,7 @@ public void setResolution(Dimension resolution) {
110140
}
111141

112142
public Dimension getResolution() {
113-
if (isMobile() && getApp() == null) {
143+
if (!isAppiumContext() && getApp() == null) {
114144
String resolution = ((RemoteWebDriver) driver).getCapabilities().getCapability("deviceScreenSize").toString();
115145
int width = Integer.parseInt(resolution.split("x")[0]);
116146
int height = Integer.parseInt(resolution.split("x")[1]);
@@ -122,14 +152,16 @@ public Dimension getResolution() {
122152
}
123153

124154
public void setZoom(int percentage) {
125-
if (percentage <= 0) {
126-
throw new IllegalArgumentException(String.format("illegal zoom percentage %s - should be greater than zero", percentage));
127-
}
128-
JavascriptExecutor jse = (JavascriptExecutor) driver;
129-
if (isFirefox()) {
130-
jse.executeScript("document.body.style.MozTransform = 'scale(" + (percentage / 100f) + ")';");
131-
} else {
132-
jse.executeScript("document.body.style.zoom = '" + percentage + "%'");
155+
if (!isAppiumContext()) {
156+
if (percentage <= 0) {
157+
throw new IllegalArgumentException(String.format("illegal zoom percentage %s - should be greater than zero", percentage));
158+
}
159+
JavascriptExecutor jse = (JavascriptExecutor) driver;
160+
if (isFirefox()) {
161+
jse.executeScript("document.body.style.MozTransform = 'scale(" + (percentage / 100f) + ")';");
162+
} else {
163+
jse.executeScript("document.body.style.zoom = '" + percentage + "%'");
164+
}
133165
}
134166

135167
}

src/main/java/net/itarray/automotion/internal/ResponsiveUIChunkValidatorBase.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
import net.itarray.automotion.validation.UISnapshot;
66
import net.itarray.automotion.validation.Units;
77
import org.json.simple.JSONObject;
8+
import org.openqa.selenium.JavascriptExecutor;
89
import org.openqa.selenium.WebElement;
910
import util.validator.ResponsiveUIValidator;
1011

1112
import java.util.List;
1213
import java.util.Map;
1314
import java.util.SortedMap;
1415
import java.util.TreeMap;
15-
import java.util.concurrent.ConcurrentSkipListMap;
16-
import java.util.concurrent.atomic.AtomicLong;
1716

1817
import static net.itarray.automotion.internal.UIElement.*;
1918

@@ -27,6 +26,12 @@ public ResponsiveUIChunkValidatorBase(UISnapshot snapshot, List<WebElement> webE
2726
if (webElements.isEmpty()) {
2827
String message = "Set root web element";
2928
addError(message);
29+
} else {
30+
if (!getDriver().isAppiumContext()) {
31+
try {
32+
((JavascriptExecutor) getDriver().getDriver()).executeScript("arguments[0].scrollIntoView();", webElements.get(0));
33+
} catch (Exception e) {}
34+
}
3035
}
3136
}
3237

src/main/java/net/itarray/automotion/internal/ResponsiveUIValidatorBase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private SimpleTransform getTransform() {
112112

113113
private double getScaleFactor() {
114114
double factor;
115-
if (isMobile()) {
115+
if (getDriver().isAppiumContext()) {
116116
factor = getReport().getRetinaScaleFactor();
117117
} else {
118118
factor = zoomFactor;
@@ -124,8 +124,8 @@ private double getScaleFactor() {
124124
}
125125

126126
private int getYOffset() {
127-
if (isMobile() && getDriver().isAppiumWebContext() && getReport().isMobileTopBarOffsetState()) {
128-
if (isIOS() || isAndroid()) {
127+
if (getDriver().isAppiumContext() && getDriver().isAppiumWebContext() && getReport().isMobileTopBarOffsetState()) {
128+
if (getDriver().isAppiumAndroidContext() || getDriver().isAppiumIOSContext()) {
129129
return (int) getReport().getMobileTopBarOffsetState();
130130
}
131131
}

src/main/java/net/itarray/automotion/internal/UIValidatorBase.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@
44
import net.itarray.automotion.internal.geometry.Rectangle;
55
import net.itarray.automotion.internal.geometry.Scalar;
66
import net.itarray.automotion.internal.properties.Context;
7-
import net.itarray.automotion.validation.properties.Expression;
87
import net.itarray.automotion.internal.properties.PixelConstant;
98
import net.itarray.automotion.validation.UIElementValidator;
109
import net.itarray.automotion.validation.UISnapshot;
1110
import net.itarray.automotion.validation.Units;
1211
import net.itarray.automotion.validation.properties.Condition;
12+
import net.itarray.automotion.validation.properties.Expression;
1313
import net.itarray.automotion.validation.properties.Padding;
1414
import org.json.simple.JSONObject;
15+
import org.openqa.selenium.JavascriptExecutor;
1516
import org.openqa.selenium.WebElement;
1617

1718
import java.util.List;
1819

19-
import static net.itarray.automotion.internal.UIElement.*;
20-
import static net.itarray.automotion.validation.properties.Expression.percentOrPixels;
21-
import static net.itarray.automotion.validation.Constants.*;
22-
import static net.itarray.automotion.validation.properties.Condition.*;
20+
import static net.itarray.automotion.internal.UIElement.asElement;
21+
import static net.itarray.automotion.internal.UIElement.asElements;
2322
import static net.itarray.automotion.internal.properties.PercentReference.PAGE;
23+
import static net.itarray.automotion.validation.Constants.*;
24+
import static net.itarray.automotion.validation.properties.Condition.greaterOrEqualTo;
25+
import static net.itarray.automotion.validation.properties.Condition.lessOrEqualTo;
26+
import static net.itarray.automotion.validation.properties.Expression.percentOrPixels;
2427

2528
public class UIValidatorBase extends ResponsiveUIValidatorBase implements UIElementValidator {
2629

@@ -33,6 +36,11 @@ public class UIValidatorBase extends ResponsiveUIValidatorBase implements UIElem
3336
public UIValidatorBase(UISnapshot snapshot, WebElement webElement, String readableNameOfElement) {
3437
super(snapshot);
3538
this.rootElement = asElement(webElement, readableNameOfElement);
39+
if (!getDriver().isAppiumContext()) {
40+
try {
41+
((JavascriptExecutor) getDriver().getDriver()).executeScript("arguments[0].scrollIntoView();", webElement);
42+
} catch (Exception e) {}
43+
}
3644
}
3745

3846
@Override

src/main/java/net/itarray/automotion/validation/UISnapshot.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import java.io.File;
1111
import java.util.List;
1212

13-
import static net.itarray.automotion.tools.environment.EnvironmentFactory.isMobile;
14-
1513
public class UISnapshot {
1614

1715
private final ResponsiveUIValidator responsiveUIValidator;
@@ -25,7 +23,7 @@ public UISnapshot(ResponsiveUIValidator responsiveUIValidator, String name, Reso
2523
this.name = name;
2624
this.resolution = resolution.queryIfUnknown(responsiveUIValidator.driver);
2725
this.zoom = zoom.queryIfUnknown(responsiveUIValidator.driver);
28-
if (!isMobile()) {
26+
if (!responsiveUIValidator.getDriver().isAppiumContext()) {
2927
resolution.applyTo(responsiveUIValidator.driver);
3028
zoom.applyTo(responsiveUIValidator.driver);
3129
}

src/test/java/ResponsiveValidatorNewDSLTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import http.helpers.EnvironmentHelper;
1+
import net.itarray.automotion.tools.driver.WebDriverFactory;
2+
import net.itarray.automotion.tools.helpers.EnvironmentHelper;
23
import net.itarray.automotion.validation.ResponsiveUIValidator;
34
import net.itarray.automotion.validation.UISnapshot;
45
import net.itarray.automotion.validation.properties.Padding;
@@ -10,15 +11,14 @@
1011
import org.openqa.selenium.WebDriver;
1112
import org.openqa.selenium.WebElement;
1213
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
13-
import util.driver.WebDriverFactory;
1414

1515
import java.awt.*;
1616
import java.util.HashMap;
1717
import java.util.Map;
1818

19+
import static net.itarray.automotion.internal.properties.PercentReference.PAGE;
1920
import static net.itarray.automotion.validation.properties.Condition.between;
2021
import static net.itarray.automotion.validation.properties.Expression.percent;
21-
import static net.itarray.automotion.internal.properties.PercentReference.PAGE;
2222
import static net.itarray.automotion.validation.properties.Zoom.zoom;
2323

2424
@Ignore

0 commit comments

Comments
 (0)