Skip to content

The addition to #738 #741

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -35,7 +35,6 @@

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

Expand All @@ -45,7 +44,6 @@ class AppiumElementLocator implements CacheableLocator {
private final By by;
private final TimeOutDuration timeOutDuration;
private final TimeOutDuration originalTimeOutDuration;
private final WebDriver originalWebDriver;
private final SearchContext searchContext;
private WebElement cachedElement;
private List<WebElement> cachedElementList;
Expand All @@ -61,29 +59,21 @@ class AppiumElementLocator implements CacheableLocator {
* 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, TimeOutDuration originalDuration) {
Copy link
Contributor

Choose a reason for hiding this comment

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

would it be possible to also replace the custom TimeOutDuration class with the native Duration one, since we anyway change method signature?

Copy link
Contributor Author

@TikhomirovSergey TikhomirovSergey Sep 30, 2017

Choose a reason for hiding this comment

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

@mykola-mokhnach
I think these parameters are needed still.

TimeOutDuration is just the container of duration values.
https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/pagefactory/TimeOutDuration.java

It was designed for the purposes like
https://github.com/TikhomirovSergey/java-client/blob/73077776d513e4521d7d5e8304469a4b85232e05/src/test/java/io/appium/java_client/pagefactory_tests/TimeOutTest.java#L122

I think it is more useful to completely change value than do 'plus' or 'minus'.
However, I think I could redesign TimeOutDuration and make it work with java.time.Duration. I think it should be done step by step. The first step is to mark some things @Deprecated and to add new good things instead, the second step is removal.

I just think that the change of TimeOutDuration may impact many users.

Copy link
Contributor

Choose a reason for hiding this comment

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

yep, I agree about we can do a separate PR for it

this.searchContext = searchContext;
this.shouldCache = shouldCache;
this.timeOutDuration = duration;
this.originalTimeOutDuration = originalDuration;
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) {
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());
Expand All @@ -94,8 +84,6 @@ private <T extends Object> T waitFor(Supplier<T> supplier) {
.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 @@ -21,30 +21,26 @@
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;

public class AppiumElementLocatorFactory implements CacheableElementLocatorFactory {
private final SearchContext searchContext;
private final TimeOutDuration timeOutDuration;
private final WebDriver originalWebDriver;
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
*/

public AppiumElementLocatorFactory(SearchContext searchContext, TimeOutDuration timeOutDuration,
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as above

WebDriver originalWebDriver, AppiumByBuilder builder) {
AppiumByBuilder builder) {
this.searchContext = searchContext;
this.originalWebDriver = originalWebDriver;
this.timeOutDuration = timeOutDuration;
this.builder = builder;
}
Expand All @@ -66,7 +62,7 @@ public CacheableLocator createLocator(Field field) {
By by = builder.buildBy();
if (by != null) {
return new AppiumElementLocator(searchContext, by, builder.isLookupCached(),
customDuration, timeOutDuration, originalWebDriver);
customDuration, timeOutDuration);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ 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;
Expand All @@ -73,9 +73,9 @@ public class AppiumFieldDecorator implements FieldDecorator {
private final HasSessionDetails hasSessionDetails;


public AppiumFieldDecorator(SearchContext context, long implicitlyWaitTimeOut,
public AppiumFieldDecorator(SearchContext context, long timeOut,
Copy link
Contributor

Choose a reason for hiding this comment

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

timeout

TimeUnit timeUnit) {
this(context, new TimeOutDuration(implicitlyWaitTimeOut, timeUnit));
this(context, new TimeOutDuration(timeOut, timeUnit));
}

/**
Expand All @@ -102,7 +102,7 @@ public AppiumFieldDecorator(SearchContext context, TimeOutDuration timeOutDurati
this.timeOutDuration = timeOutDuration;

defaultElementFieldDecoracor = new DefaultFieldDecorator(
new AppiumElementLocatorFactory(context, timeOutDuration, originalDriver,
new AppiumElementLocatorFactory(context, timeOutDuration,
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, timeOutDuration, new WidgetByBuilder(platform, automation));
}

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

/**
Expand Down
34 changes: 34 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,34 @@
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() {
Path resultPath;
Platform current = getCurrent();

if (current.is(WINDOWS)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why cannot we use switch () case ...: return here? this will allow to get rid of many temporary variables

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mykola-mokhnach

Because there may be WINDOWS8, WINDOWS10, WINDOWS_XP etc. I think that it is easier to compare current platforn with WINDOWS (the result for WINDOWS8, WINDOWS10, WINDOWS_XP is TRUE)

Copy link
Contributor

Choose a reason for hiding this comment

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

np if you prefer this. However it still can be simplified by retuning the value immediately inside if block

resultPath = ROOT_TEST_PATH.resolve("chromedriver.exe");
} else if (current.is(MAC)) {
resultPath = ROOT_TEST_PATH.resolve("chromedriver_mac");
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

this else is not needed

resultPath = ROOT_TEST_PATH.resolve("chromedriver_linux");
}

return resultPath.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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class MobileBrowserCompatibilityTest {
private AppiumDriverLocalService service;

@AndroidFindBy(className = "someClass") @AndroidFindBy(xpath = "//someTag")
private RemoteWebElement btnG; //this element should be found by id = 'btnG' or name = 'btnG'
private RemoteWebElement btnK; //this element should be found by id = 'btnG' or name = 'btnG'
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is changed, then the comment should also be changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. I will improve it a bit later.


@FindBy(name = "q")
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/someId\")")
Expand Down Expand Up @@ -87,7 +87,7 @@ public class MobileBrowserCompatibilityTest {
driver.get("https://www.google.com");

searchTextField.sendKeys("Hello");
btnG.click();
btnK.click();
Assert.assertNotEquals(0, foundLinks.size());
}

Expand Down
Loading