Skip to content

Commit 3229163

Browse files
Merge pull request #741 from TikhomirovSergey/titusfortner-explicit
The addition to #738
2 parents b68ec85 + 2419dca commit 3229163

File tree

14 files changed

+214
-231
lines changed

14 files changed

+214
-231
lines changed

build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ apply plugin: 'signing'
88
apply plugin: 'maven-publish'
99

1010
group 'io.appium'
11-
version '5.0.3'
11+
version '5.0.4'
1212

1313
repositories {
1414
jcenter()
@@ -54,7 +54,7 @@ compileJava {
5454
]
5555
}
5656

57-
ext.seleniumVersion = '3.5.3'
57+
ext.seleniumVersion = '3.6.0'
5858

5959
dependencies {
6060
compile ("org.seleniumhq.selenium:selenium-java:${seleniumVersion}") {
@@ -73,14 +73,14 @@ dependencies {
7373
compile ("org.seleniumhq.selenium:selenium-api:${seleniumVersion}") {
7474
force = true
7575
}
76-
compile 'com.google.code.gson:gson:2.8.1'
76+
compile 'com.google.code.gson:gson:2.8.2'
7777
compile 'org.apache.httpcomponents:httpclient:4.5.3'
7878
compile 'cglib:cglib:3.2.5'
7979
compile 'commons-validator:commons-validator:1.6'
8080
compile 'org.apache.commons:commons-lang3:3.6'
8181
compile 'commons-io:commons-io:2.5'
82-
compile 'org.springframework:spring-context:4.3.10.RELEASE'
83-
compile 'org.aspectj:aspectjweaver:1.8.10'
82+
compile 'org.springframework:spring-context:5.0.0.RELEASE'
83+
compile 'org.aspectj:aspectjweaver:1.8.11'
8484
compile 'org.openpnp:opencv:3.2.0-1'
8585

8686
testCompile 'junit:junit:4.12'

src/main/java/io/appium/java_client/ios/PushesFiles.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package io.appium.java_client.ios;
1818

19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
import static io.appium.java_client.MobileCommand.pushFileCommand;
21+
1922
import io.appium.java_client.CommandExecutionHelper;
2023
import io.appium.java_client.ExecutesMethod;
2124
import org.apache.commons.codec.binary.Base64;
@@ -24,9 +27,6 @@
2427
import java.io.File;
2528
import java.io.IOException;
2629

27-
import static com.google.common.base.Preconditions.checkNotNull;
28-
import static io.appium.java_client.MobileCommand.pushFileCommand;
29-
3030
public interface PushesFiles extends ExecutesMethod {
3131

3232
/**

src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,20 @@
2828
import org.openqa.selenium.SearchContext;
2929
import org.openqa.selenium.StaleElementReferenceException;
3030
import org.openqa.selenium.TimeoutException;
31-
import org.openqa.selenium.WebDriver;
3231
import org.openqa.selenium.WebDriverException;
3332
import org.openqa.selenium.WebElement;
3433
import org.openqa.selenium.support.ui.FluentWait;
3534

3635
import java.util.ArrayList;
3736
import java.util.List;
38-
import java.util.concurrent.TimeUnit;
3937
import java.util.function.Function;
4038
import java.util.function.Supplier;
4139

4240
class AppiumElementLocator implements CacheableLocator {
4341

4442
private final boolean shouldCache;
4543
private final By by;
46-
private final TimeOutDuration timeOutDuration;
47-
private final TimeOutDuration originalTimeOutDuration;
48-
private final WebDriver originalWebDriver;
44+
private final TimeOutDuration duration;
4945
private final SearchContext searchContext;
5046
private WebElement cachedElement;
5147
private List<WebElement> cachedElementList;
@@ -60,42 +56,30 @@ class AppiumElementLocator implements CacheableLocator {
6056
* @param shouldCache is the flag that signalizes that elements which
6157
* are found once should be cached
6258
* @param duration is a POJO which contains timeout parameters for the element to be searched
63-
* @param originalDuration is a POJO which contains timeout parameters from page object which contains the element
64-
* @param originalWebDriver is an instance of WebDriver that is going to be
65-
* used by a proxied element
6659
*/
6760

6861
public AppiumElementLocator(SearchContext searchContext, By by, boolean shouldCache,
69-
TimeOutDuration duration, TimeOutDuration originalDuration, WebDriver originalWebDriver) {
62+
TimeOutDuration duration) {
7063
this.searchContext = searchContext;
7164
this.shouldCache = shouldCache;
72-
this.timeOutDuration = duration;
73-
this.originalTimeOutDuration = originalDuration;
65+
this.duration = duration;
7466
this.by = by;
75-
this.originalWebDriver = originalWebDriver;
7667
this.exceptionMessageIfElementNotFound = "Can't locate an element by this strategy: " + by.toString();
7768
}
7869

79-
private void changeImplicitlyWaitTimeOut(long newTimeOut, TimeUnit newTimeUnit) {
80-
originalWebDriver.manage().timeouts().implicitlyWait(newTimeOut, newTimeUnit);
81-
}
82-
83-
private <T extends Object> T waitFor(Supplier<T> supplier) {
70+
private <T> T waitFor(Supplier<T> supplier) {
8471
WaitingFunction<T> function = new WaitingFunction<>();
8572
try {
86-
changeImplicitlyWaitTimeOut(0, TimeUnit.SECONDS);
8773
FluentWait<Supplier<T>> wait = new FluentWait<>(supplier)
8874
.ignoring(NoSuchElementException.class);
89-
wait.withTimeout(timeOutDuration.getTime(), timeOutDuration.getTimeUnit());
75+
wait.withTimeout(duration.getTime(), duration.getTimeUnit());
9076
return wait.until(function);
9177
} catch (TimeoutException e) {
9278
if (function.foundStaleElementReferenceException != null) {
9379
throw StaleElementReferenceException
9480
.class.cast(function.foundStaleElementReferenceException);
9581
}
9682
throw e;
97-
} finally {
98-
changeImplicitlyWaitTimeOut(originalTimeOutDuration.getTime(), originalTimeOutDuration.getTimeUnit());
9983
}
10084
}
10185

src/main/java/io/appium/java_client/pagefactory/AppiumElementLocatorFactory.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,59 +16,57 @@
1616

1717
package io.appium.java_client.pagefactory;
1818

19+
import static java.util.Optional.ofNullable;
20+
1921
import io.appium.java_client.pagefactory.bys.builder.AppiumByBuilder;
2022
import io.appium.java_client.pagefactory.locator.CacheableElementLocatorFactory;
2123
import io.appium.java_client.pagefactory.locator.CacheableLocator;
2224
import org.openqa.selenium.By;
2325
import org.openqa.selenium.SearchContext;
24-
import org.openqa.selenium.WebDriver;
2526

2627
import java.lang.reflect.AnnotatedElement;
2728
import java.lang.reflect.Field;
29+
import javax.annotation.Nullable;
2830

2931
public class AppiumElementLocatorFactory implements CacheableElementLocatorFactory {
3032
private final SearchContext searchContext;
31-
private final TimeOutDuration timeOutDuration;
32-
private final WebDriver originalWebDriver;
33+
private final TimeOutDuration duration;
3334
private final AppiumByBuilder builder;
3435

3536
/**
3637
* Creates a new mobile element locator factory.
3738
*
3839
* @param searchContext The context to use when finding the element
39-
* @param timeOutDuration is a POJO which contains timeout parameters for the element to be searched
40-
* @param originalWebDriver is an instance of WebDriver that is going to be used by a proxied element
41-
* @param builder is handler of Appium-specific page object annotations
40+
* @param duration is a POJO which contains timeout parameters for the element to be searched
41+
* @param builder is handler of Appium-specific page object annotations
4242
*/
4343

44-
public AppiumElementLocatorFactory(SearchContext searchContext, TimeOutDuration timeOutDuration,
45-
WebDriver originalWebDriver, AppiumByBuilder builder) {
44+
public AppiumElementLocatorFactory(SearchContext searchContext, TimeOutDuration duration,
45+
AppiumByBuilder builder) {
4646
this.searchContext = searchContext;
47-
this.originalWebDriver = originalWebDriver;
48-
this.timeOutDuration = timeOutDuration;
47+
this.duration = duration;
4948
this.builder = builder;
5049
}
5150

52-
public CacheableLocator createLocator(Field field) {
51+
public @Nullable CacheableLocator createLocator(Field field) {
5352
return this.createLocator((AnnotatedElement) field);
5453
}
5554

56-
@Override public CacheableLocator createLocator(AnnotatedElement annotatedElement) {
55+
@Override public @Nullable CacheableLocator createLocator(AnnotatedElement annotatedElement) {
5756
TimeOutDuration customDuration;
5857
if (annotatedElement.isAnnotationPresent(WithTimeout.class)) {
5958
WithTimeout withTimeout = annotatedElement.getAnnotation(WithTimeout.class);
6059
customDuration = new TimeOutDuration(withTimeout.time(), withTimeout.unit());
6160
} else {
62-
customDuration = timeOutDuration;
61+
customDuration = duration;
6362
}
6463

6564
builder.setAnnotated(annotatedElement);
66-
By by = builder.buildBy();
67-
if (by != null) {
68-
return new AppiumElementLocator(searchContext, by, builder.isLookupCached(),
69-
customDuration, timeOutDuration, originalWebDriver);
70-
}
71-
return null;
65+
By byResult = builder.buildBy();
66+
67+
return ofNullable(byResult)
68+
.map(by -> new AppiumElementLocator(searchContext, by, builder.isLookupCached(), customDuration))
69+
.orElse(null);
7270
}
7371

7472

src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ public class AppiumFieldDecorator implements FieldDecorator {
6262
private static final List<Class<? extends WebElement>> availableElementClasses = ImmutableList.of(WebElement.class,
6363
RemoteWebElement.class, MobileElement.class, AndroidElement.class,
6464
IOSElement.class, WindowsElement.class);
65-
public static long DEFAULT_IMPLICITLY_WAIT_TIMEOUT = 1;
65+
public static long DEFAULT_TIMEOUT = 1;
6666
public static TimeUnit DEFAULT_TIMEUNIT = TimeUnit.SECONDS;
6767
private final WebDriver originalDriver;
6868
private final DefaultFieldDecorator defaultElementFieldDecoracor;
6969
private final AppiumElementLocatorFactory widgetLocatorFactory;
7070
private final String platform;
7171
private final String automation;
72-
private final TimeOutDuration timeOutDuration;
72+
private final TimeOutDuration duration;
7373
private final HasSessionDetails hasSessionDetails;
7474

7575

76-
public AppiumFieldDecorator(SearchContext context, long implicitlyWaitTimeOut,
76+
public AppiumFieldDecorator(SearchContext context, long timeout,
7777
TimeUnit timeUnit) {
78-
this(context, new TimeOutDuration(implicitlyWaitTimeOut, timeUnit));
78+
this(context, new TimeOutDuration(timeout, timeUnit));
7979
}
8080

8181
/**
@@ -84,9 +84,9 @@ public AppiumFieldDecorator(SearchContext context, long implicitlyWaitTimeOut,
8484
* or {@link org.openqa.selenium.WebElement} or
8585
* {@link io.appium.java_client.pagefactory.Widget} or some other user's
8686
* extension/implementation.
87-
* @param timeOutDuration is a desired duration of the waiting for an element presence.
87+
* @param duration is a desired duration of the waiting for an element presence.
8888
*/
89-
public AppiumFieldDecorator(SearchContext context, TimeOutDuration timeOutDuration) {
89+
public AppiumFieldDecorator(SearchContext context, TimeOutDuration duration) {
9090
this.originalDriver = unpackWebDriverFromSearchContext(context);
9191
if (originalDriver == null
9292
|| !HasSessionDetails.class.isAssignableFrom(originalDriver.getClass())) {
@@ -99,10 +99,10 @@ public AppiumFieldDecorator(SearchContext context, TimeOutDuration timeOutDurati
9999
automation = hasSessionDetails.getAutomationName();
100100
}
101101

102-
this.timeOutDuration = timeOutDuration;
102+
this.duration = duration;
103103

104104
defaultElementFieldDecoracor = new DefaultFieldDecorator(
105-
new AppiumElementLocatorFactory(context, timeOutDuration, originalDriver,
105+
new AppiumElementLocatorFactory(context, duration,
106106
new DefaultElementByBuilder(platform, automation))) {
107107
@Override
108108
protected WebElement proxyForLocator(ClassLoader ignored, ElementLocator locator) {
@@ -139,12 +139,11 @@ protected List<WebElement> proxyForListLocator(ClassLoader ignored,
139139
};
140140

141141
widgetLocatorFactory =
142-
new AppiumElementLocatorFactory(context, timeOutDuration, originalDriver,
143-
new WidgetByBuilder(platform, automation));
142+
new AppiumElementLocatorFactory(context, duration, new WidgetByBuilder(platform, automation));
144143
}
145144

146145
public AppiumFieldDecorator(SearchContext context) {
147-
this(context, DEFAULT_IMPLICITLY_WAIT_TIMEOUT, DEFAULT_TIMEUNIT);
146+
this(context, DEFAULT_TIMEOUT, DEFAULT_TIMEUNIT);
148147
}
149148

150149
/**
@@ -204,14 +203,14 @@ private Object decorateWidget(Field field) {
204203
if (isAlist) {
205204
return getEnhancedProxy(ArrayList.class,
206205
new WidgetListInterceptor(locator, originalDriver, map, widgetType,
207-
timeOutDuration));
206+
duration));
208207
}
209208

210209
Constructor<? extends Widget> constructor =
211210
WidgetConstructorUtil.findConvenientConstructor(widgetType);
212211
return getEnhancedProxy(widgetType, new Class[] {constructor.getParameterTypes()[0]},
213212
new Object[] {proxyForAnElement(locator)},
214-
new WidgetInterceptor(locator, originalDriver, null, map, timeOutDuration));
213+
new WidgetInterceptor(locator, originalDriver, null, map, duration));
215214
}
216215

217216
private WebElement proxyForAnElement(ElementLocator locator) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.appium.java_client;
2+
3+
import static java.nio.file.FileSystems.getDefault;
4+
import static org.openqa.selenium.Platform.MAC;
5+
import static org.openqa.selenium.Platform.WINDOWS;
6+
import static org.openqa.selenium.Platform.getCurrent;
7+
8+
import org.openqa.selenium.Platform;
9+
10+
import java.io.File;
11+
import java.nio.file.Path;
12+
13+
public final class ChromeDriverPathUtil {
14+
private static final Path ROOT_TEST_PATH = getDefault().getPath("src")
15+
.resolve("test").resolve("java").resolve("io").resolve("appium").resolve("java_client");
16+
17+
/**
18+
* @return the choromedriver file which depends on platform.
19+
*/
20+
public static File getChromeDriver() {
21+
Platform current = getCurrent();
22+
if (current.is(WINDOWS)) {
23+
return ROOT_TEST_PATH.resolve("chromedriver.exe").toFile();
24+
} else if (current.is(MAC)) {
25+
return ROOT_TEST_PATH.resolve("chromedriver_mac").toFile();
26+
}
27+
28+
return ROOT_TEST_PATH.resolve("chromedriver_linux").toFile();
29+
}
30+
}
8.5 MB
Binary file not shown.

src/test/java/io/appium/java_client/pagefactory_tests/chromedriver renamed to src/test/java/io/appium/java_client/chromedriver_mac

10.3 MB
Binary file not shown.

src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
package io.appium.java_client.pagefactory_tests;
1818

19+
import static io.appium.java_client.ChromeDriverPathUtil.getChromeDriver;
1920
import static io.appium.java_client.pagefactory.LocatorGroupStrategy.ALL_POSSIBLE;
21+
import static java.lang.System.setProperty;
2022
import static org.junit.Assert.assertEquals;
2123
import static org.junit.Assert.assertNotEquals;
2224

@@ -27,7 +29,6 @@
2729
import io.appium.java_client.pagefactory.iOSFindBy;
2830
import org.junit.BeforeClass;
2931
import org.junit.Test;
30-
import org.openqa.selenium.Platform;
3132
import org.openqa.selenium.WebDriver;
3233
import org.openqa.selenium.WebElement;
3334
import org.openqa.selenium.chrome.ChromeDriver;
@@ -42,8 +43,6 @@
4243

4344
public class DesktopBrowserCompatibilityTest {
4445

45-
46-
private static final Platform current = Platform.getCurrent();
4746
@HowToUseLocators(iOSAutomation = ALL_POSSIBLE)
4847
@AndroidFindBy(className = "someClass")
4948
@iOSFindBy(xpath = "//selector[1]") @iOSFindBy(xpath = "//someTag")
@@ -57,13 +56,8 @@ public class DesktopBrowserCompatibilityTest {
5756
* The starting.
5857
*/
5958
@BeforeClass public static void beforeClass() {
60-
if (current.is(Platform.WINDOWS)) {
61-
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
62-
"src/test/java/io/appium/java_client/pagefactory_tests/chromedriver.exe");
63-
} else {
64-
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
65-
"src/test/java/io/appium/java_client/pagefactory_tests/chromedriver");
66-
}
59+
setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
60+
getChromeDriver().getAbsolutePath());
6761
}
6862

6963
@Test public void chromeTest() {

0 commit comments

Comments
 (0)