Skip to content

The addition to #738 #741

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 5 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apply plugin: 'signing'
apply plugin: 'maven-publish'

group 'io.appium'
version '5.0.3'
version '5.0.4'

repositories {
jcenter()
Expand Down Expand Up @@ -54,7 +54,7 @@ compileJava {
]
}

ext.seleniumVersion = '3.5.3'
ext.seleniumVersion = '3.6.0'

dependencies {
compile ("org.seleniumhq.selenium:selenium-java:${seleniumVersion}") {
Expand All @@ -73,14 +73,14 @@ dependencies {
compile ("org.seleniumhq.selenium:selenium-api:${seleniumVersion}") {
force = true
}
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.google.code.gson:gson:2.8.2'
compile 'org.apache.httpcomponents:httpclient:4.5.3'
compile 'cglib:cglib:3.2.5'
compile 'commons-validator:commons-validator:1.6'
compile 'org.apache.commons:commons-lang3:3.6'
compile 'commons-io:commons-io:2.5'
compile 'org.springframework:spring-context:4.3.10.RELEASE'
compile 'org.aspectj:aspectjweaver:1.8.10'
compile 'org.springframework:spring-context:5.0.0.RELEASE'
compile 'org.aspectj:aspectjweaver:1.8.11'
compile 'org.openpnp:opencv:3.2.0-1'

testCompile 'junit:junit:4.12'
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/appium/java_client/ios/PushesFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package io.appium.java_client.ios;

import static com.google.common.base.Preconditions.checkNotNull;
import static io.appium.java_client.MobileCommand.pushFileCommand;

import io.appium.java_client.CommandExecutionHelper;
import io.appium.java_client.ExecutesMethod;
import org.apache.commons.codec.binary.Base64;
Expand All @@ -24,9 +27,6 @@
import java.io.File;
import java.io.IOException;

import static com.google.common.base.Preconditions.checkNotNull;
import static io.appium.java_client.MobileCommand.pushFileCommand;

public interface PushesFiles extends ExecutesMethod {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,20 @@
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.FluentWait;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;

class AppiumElementLocator implements CacheableLocator {

private final boolean shouldCache;
private final By by;
private final TimeOutDuration timeOutDuration;
private final TimeOutDuration originalTimeOutDuration;
private final WebDriver originalWebDriver;
private final TimeOutDuration duration;
private final SearchContext searchContext;
private WebElement cachedElement;
private List<WebElement> cachedElementList;
Expand All @@ -60,42 +56,30 @@ class AppiumElementLocator implements CacheableLocator {
* @param shouldCache is the flag that signalizes that elements which
* are found once should be cached
* @param duration is a POJO which contains timeout parameters for the element to be searched
* @param originalDuration is a POJO which contains timeout parameters from page object which contains the element
* @param originalWebDriver is an instance of WebDriver that is going to be
* used by a proxied element
*/

public AppiumElementLocator(SearchContext searchContext, By by, boolean shouldCache,
TimeOutDuration duration, TimeOutDuration originalDuration, WebDriver originalWebDriver) {
TimeOutDuration duration) {
this.searchContext = searchContext;
this.shouldCache = shouldCache;
this.timeOutDuration = duration;
this.originalTimeOutDuration = originalDuration;
this.duration = duration;
this.by = by;
this.originalWebDriver = originalWebDriver;
this.exceptionMessageIfElementNotFound = "Can't locate an element by this strategy: " + by.toString();
}

private void changeImplicitlyWaitTimeOut(long newTimeOut, TimeUnit newTimeUnit) {
originalWebDriver.manage().timeouts().implicitlyWait(newTimeOut, newTimeUnit);
}

private <T extends Object> T waitFor(Supplier<T> supplier) {
private <T> T waitFor(Supplier<T> supplier) {
WaitingFunction<T> function = new WaitingFunction<>();
try {
changeImplicitlyWaitTimeOut(0, TimeUnit.SECONDS);
FluentWait<Supplier<T>> wait = new FluentWait<>(supplier)
.ignoring(NoSuchElementException.class);
wait.withTimeout(timeOutDuration.getTime(), timeOutDuration.getTimeUnit());
wait.withTimeout(duration.getTime(), duration.getTimeUnit());
return wait.until(function);
} catch (TimeoutException e) {
if (function.foundStaleElementReferenceException != null) {
throw StaleElementReferenceException
.class.cast(function.foundStaleElementReferenceException);
}
throw e;
} finally {
changeImplicitlyWaitTimeOut(originalTimeOutDuration.getTime(), originalTimeOutDuration.getTimeUnit());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,57 @@

package io.appium.java_client.pagefactory;

import static java.util.Optional.ofNullable;

import io.appium.java_client.pagefactory.bys.builder.AppiumByBuilder;
import io.appium.java_client.pagefactory.locator.CacheableElementLocatorFactory;
import io.appium.java_client.pagefactory.locator.CacheableLocator;
import org.openqa.selenium.By;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import javax.annotation.Nullable;

public class AppiumElementLocatorFactory implements CacheableElementLocatorFactory {
private final SearchContext searchContext;
private final TimeOutDuration timeOutDuration;
private final WebDriver originalWebDriver;
private final TimeOutDuration duration;
private final AppiumByBuilder builder;

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

public AppiumElementLocatorFactory(SearchContext searchContext, TimeOutDuration timeOutDuration,
WebDriver originalWebDriver, AppiumByBuilder builder) {
public AppiumElementLocatorFactory(SearchContext searchContext, TimeOutDuration duration,
AppiumByBuilder builder) {
this.searchContext = searchContext;
this.originalWebDriver = originalWebDriver;
this.timeOutDuration = timeOutDuration;
this.duration = duration;
this.builder = builder;
}

public CacheableLocator createLocator(Field field) {
public @Nullable CacheableLocator createLocator(Field field) {
return this.createLocator((AnnotatedElement) field);
}

@Override public CacheableLocator createLocator(AnnotatedElement annotatedElement) {
@Override public @Nullable CacheableLocator createLocator(AnnotatedElement annotatedElement) {
TimeOutDuration customDuration;
if (annotatedElement.isAnnotationPresent(WithTimeout.class)) {
WithTimeout withTimeout = annotatedElement.getAnnotation(WithTimeout.class);
customDuration = new TimeOutDuration(withTimeout.time(), withTimeout.unit());
} else {
customDuration = timeOutDuration;
customDuration = duration;
}

builder.setAnnotated(annotatedElement);
By by = builder.buildBy();
if (by != null) {
return new AppiumElementLocator(searchContext, by, builder.isLookupCached(),
customDuration, timeOutDuration, originalWebDriver);
}
return null;
By byResult = builder.buildBy();

return ofNullable(byResult)
.map(by -> new AppiumElementLocator(searchContext, by, builder.isLookupCached(), customDuration))
.orElse(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method can be marked as Nullable

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ public class AppiumFieldDecorator implements FieldDecorator {
private static final List<Class<? extends WebElement>> availableElementClasses = ImmutableList.of(WebElement.class,
RemoteWebElement.class, MobileElement.class, AndroidElement.class,
IOSElement.class, WindowsElement.class);
public static long DEFAULT_IMPLICITLY_WAIT_TIMEOUT = 1;
public static long DEFAULT_TIMEOUT = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can deprecate the constant of TimeUnit type if we use Duration type for DEFAULT_TIMEOUT

public static TimeUnit DEFAULT_TIMEUNIT = TimeUnit.SECONDS;
private final WebDriver originalDriver;
private final DefaultFieldDecorator defaultElementFieldDecoracor;
private final AppiumElementLocatorFactory widgetLocatorFactory;
private final String platform;
private final String automation;
private final TimeOutDuration timeOutDuration;
private final TimeOutDuration duration;
private final HasSessionDetails hasSessionDetails;


public AppiumFieldDecorator(SearchContext context, long implicitlyWaitTimeOut,
public AppiumFieldDecorator(SearchContext context, long timeout,
TimeUnit timeUnit) {
this(context, new TimeOutDuration(implicitlyWaitTimeOut, timeUnit));
this(context, new TimeOutDuration(timeout, timeUnit));
}

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

this.timeOutDuration = timeOutDuration;
this.duration = duration;

defaultElementFieldDecoracor = new DefaultFieldDecorator(
new AppiumElementLocatorFactory(context, timeOutDuration, originalDriver,
new AppiumElementLocatorFactory(context, duration,
new DefaultElementByBuilder(platform, automation))) {
@Override
protected WebElement proxyForLocator(ClassLoader ignored, ElementLocator locator) {
Expand Down Expand Up @@ -139,12 +139,11 @@ protected List<WebElement> proxyForListLocator(ClassLoader ignored,
};

widgetLocatorFactory =
new AppiumElementLocatorFactory(context, timeOutDuration, originalDriver,
new WidgetByBuilder(platform, automation));
new AppiumElementLocatorFactory(context, duration, new WidgetByBuilder(platform, automation));
}

public AppiumFieldDecorator(SearchContext context) {
this(context, DEFAULT_IMPLICITLY_WAIT_TIMEOUT, DEFAULT_TIMEUNIT);
this(context, DEFAULT_TIMEOUT, DEFAULT_TIMEUNIT);
}

/**
Expand Down Expand Up @@ -204,14 +203,14 @@ private Object decorateWidget(Field field) {
if (isAlist) {
return getEnhancedProxy(ArrayList.class,
new WidgetListInterceptor(locator, originalDriver, map, widgetType,
timeOutDuration));
duration));
}

Constructor<? extends Widget> constructor =
WidgetConstructorUtil.findConvenientConstructor(widgetType);
return getEnhancedProxy(widgetType, new Class[] {constructor.getParameterTypes()[0]},
new Object[] {proxyForAnElement(locator)},
new WidgetInterceptor(locator, originalDriver, null, map, timeOutDuration));
new WidgetInterceptor(locator, originalDriver, null, map, duration));
}

private WebElement proxyForAnElement(ElementLocator locator) {
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/io/appium/java_client/ChromeDriverPathUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.appium.java_client;

import static java.nio.file.FileSystems.getDefault;
import static org.openqa.selenium.Platform.MAC;
import static org.openqa.selenium.Platform.WINDOWS;
import static org.openqa.selenium.Platform.getCurrent;

import org.openqa.selenium.Platform;

import java.io.File;
import java.nio.file.Path;

public final class ChromeDriverPathUtil {
private static final Path ROOT_TEST_PATH = getDefault().getPath("src")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

.resolve("test").resolve("java").resolve("io").resolve("appium").resolve("java_client");

/**
* @return the choromedriver file which depends on platform.
*/
public static File getChromeDriver() {
Platform current = getCurrent();
if (current.is(WINDOWS)) {
return ROOT_TEST_PATH.resolve("chromedriver.exe").toFile();
} else if (current.is(MAC)) {
return ROOT_TEST_PATH.resolve("chromedriver_mac").toFile();
}

return ROOT_TEST_PATH.resolve("chromedriver_linux").toFile();
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package io.appium.java_client.pagefactory_tests;

import static io.appium.java_client.ChromeDriverPathUtil.getChromeDriver;
import static io.appium.java_client.pagefactory.LocatorGroupStrategy.ALL_POSSIBLE;
import static java.lang.System.setProperty;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

Expand All @@ -27,7 +29,6 @@
import io.appium.java_client.pagefactory.iOSFindBy;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
Expand All @@ -42,8 +43,6 @@

public class DesktopBrowserCompatibilityTest {


private static final Platform current = Platform.getCurrent();
@HowToUseLocators(iOSAutomation = ALL_POSSIBLE)
@AndroidFindBy(className = "someClass")
@iOSFindBy(xpath = "//selector[1]") @iOSFindBy(xpath = "//someTag")
Expand All @@ -57,13 +56,8 @@ public class DesktopBrowserCompatibilityTest {
* The starting.
*/
@BeforeClass public static void beforeClass() {
if (current.is(Platform.WINDOWS)) {
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
"src/test/java/io/appium/java_client/pagefactory_tests/chromedriver.exe");
} else {
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
"src/test/java/io/appium/java_client/pagefactory_tests/chromedriver");
}
setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
getChromeDriver().getAbsolutePath());
}

@Test public void chromeTest() {
Expand Down
Loading