Skip to content
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ compileJava {
]
}

ext.seleniumVersion = '3.13.0'
ext.seleniumVersion = '3.14.0'

dependencies {
compile ("org.seleniumhq.selenium:selenium-java:${seleniumVersion}") {
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/io/appium/java_client/AppiumFluentWait.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@

package io.appium.java_client;

import static java.time.Duration.ofMillis;

import com.google.common.base.Throwables;

import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.support.ui.Clock;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Sleeper;

import java.lang.reflect.Field;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
Expand Down Expand Up @@ -228,8 +227,8 @@ public AppiumFluentWait<T> withPollingStrategy(Function<IterationInfo, Duration>
*/
@Override
public <V> V until(Function<? super T, V> isTrue) {
final long start = getClock().now();
final long end = getClock().laterBy(getTimeout().toMillis());
final Instant start = getClock().instant();
final Instant end = getClock().instant().plus(getTimeout());
long iterationNumber = 1;
Throwable lastException;
while (true) {
Expand All @@ -249,7 +248,7 @@ public <V> V until(Function<? super T, V> isTrue) {

// Check the timeout after evaluating the function to ensure conditions
// with a zero timeout can succeed.
if (!getClock().isNowBefore(end)) {
if (end.isBefore(getClock().instant())) {
String message = getMessageSupplier() != null ? getMessageSupplier().get() : null;

String timeoutMessage = String.format(
Expand All @@ -263,7 +262,7 @@ public <V> V until(Function<? super T, V> isTrue) {
Duration interval = getInterval();
if (pollingStrategy != null) {
final IterationInfo info = new IterationInfo(iterationNumber,
ofMillis(getClock().now() - start), getTimeout(),
Duration.between(start, getClock().instant()), getTimeout(),
interval);
interval = pollingStrategy.apply(info);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.appium.java_client.MobileCommand;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.internal.HasIdentity;
import org.openqa.selenium.remote.RemoteWebElement;

import java.util.AbstractMap;
import java.util.Map;
Expand Down Expand Up @@ -267,15 +267,15 @@ public class AndroidMobileCommandHelper extends MobileCommand {
* This method forms a {@link Map} of parameters for the element
* value replacement. It is used against input elements
*
* @param hasIdentityObject an instance which contains an element ID
* @param remoteWebElement an instance which contains an element ID
* @param value a new value
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
public static Map.Entry<String, Map<String, ?>> replaceElementValueCommand(
HasIdentity hasIdentityObject, String value) {
RemoteWebElement remoteWebElement, String value) {
String[] parameters = new String[] {"id", "value"};
Object[] values =
new Object[] {hasIdentityObject.getId(), value};
new Object[] {remoteWebElement.getId(), value};

return new AbstractMap.SimpleEntry<>(
REPLACE_VALUE, prepareArguments(parameters, values));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.WrapsDriver;
import org.openqa.selenium.WrapsDriver;
import org.openqa.selenium.internal.WrapsElement;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
import net.sf.cglib.proxy.MethodProxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.WrapsDriver;
import org.openqa.selenium.WrapsDriver;
import org.openqa.selenium.support.pagefactory.ElementLocator;

import java.lang.reflect.Method;


public abstract class InterceptorOfASingleElement implements MethodInterceptor {
protected final ElementLocator locator;
protected final WebDriver driver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.openqa.selenium.ContextAware;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.internal.WrapsDriver;
import org.openqa.selenium.WrapsDriver;
import org.openqa.selenium.internal.WrapsElement;

public final class WebDriverUnpackUtility {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,

public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
URL addressOfRemoteServer) {
this(additionalCommands, addressOfRemoteServer, new AppiumHttpClientFactory());
this(additionalCommands, addressOfRemoteServer, HttpClient.Factory.createDefault());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason to revert that?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The issue was fixed in Selenium: SeleniumHQ/selenium@550cd0c, so no reason to keep this workaround

}

public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
DriverService service) {
this(additionalCommands, service, new AppiumHttpClientFactory());
this(additionalCommands, service, HttpClient.Factory.createDefault());
}

protected <B> B getPrivateFieldValue(String fieldName, Class<B> fieldType) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.HasIdentity;
import org.openqa.selenium.remote.RemoteWebElement;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -60,9 +60,9 @@ public ElementOption withCoordinates(int xOffset, int yOffset) {
public ElementOption withElement(WebElement element) {
checkNotNull(element);
checkArgument(true, "Element should be an instance of the class which "
+ "implements org.openqa.selenium.internal.HasIdentity",
(HasIdentity.class.isAssignableFrom(element.getClass())));
elementId = HasIdentity.class.cast(element).getId();
+ "extends org.openqa.selenium.remote.RemoteWebElement",
(RemoteWebElement.class.isAssignableFrom(element.getClass())));
elementId = RemoteWebElement.class.cast(element).getId();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.support.ui.SystemClock;
import org.openqa.selenium.support.ui.Wait;

import java.time.Clock;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;

Expand All @@ -43,7 +43,7 @@ public boolean isDisplayed() {
@Test(expected = TimeoutException.class)
public void testDefaultStrategy() {
final FakeElement el = new FakeElement();
final Wait<FakeElement> wait = new AppiumFluentWait<>(el, new SystemClock(), duration -> {
final Wait<FakeElement> wait = new AppiumFluentWait<>(el, Clock.systemDefaultZone(), duration -> {
assertThat(duration.getSeconds(), is(equalTo(1L)));
Thread.sleep(duration.toMillis());
}).withPollingStrategy(AppiumFluentWait.IterationInfo::getInterval)
Expand All @@ -57,7 +57,7 @@ public void testDefaultStrategy() {
public void testCustomStrategyOverridesDefaultInterval() {
final FakeElement el = new FakeElement();
final AtomicInteger callsCounter = new AtomicInteger(0);
final Wait<FakeElement> wait = new AppiumFluentWait<>(el, new SystemClock(), duration -> {
final Wait<FakeElement> wait = new AppiumFluentWait<>(el, Clock.systemDefaultZone(), duration -> {
callsCounter.incrementAndGet();
assertThat(duration.getSeconds(), is(equalTo(2L)));
Thread.sleep(duration.toMillis());
Expand All @@ -79,7 +79,7 @@ public void testIntervalCalculationForCustomStrategy() {
final AtomicInteger callsCounter = new AtomicInteger(0);
// Linear dependency
final Function<Long, Long> pollingStrategy = x -> x * 2;
final Wait<FakeElement> wait = new AppiumFluentWait<>(el, new SystemClock(), duration -> {
final Wait<FakeElement> wait = new AppiumFluentWait<>(el, Clock.systemDefaultZone(), duration -> {
int callNumber = callsCounter.incrementAndGet();
assertThat(duration.getSeconds(), is(equalTo(pollingStrategy.apply((long) callNumber))));
Thread.sleep(duration.toMillis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.junit.Test;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.WrapsDriver;
import org.openqa.selenium.WrapsDriver;
import org.openqa.selenium.remote.RemoteWebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.WrapsDriver;
import org.openqa.selenium.WrapsDriver;

import java.util.List;

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/io/appium/java_client/touch/DummyElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import org.openqa.selenium.Point;
import org.openqa.selenium.Rectangle;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.HasIdentity;
import org.openqa.selenium.remote.RemoteWebElement;

import java.util.List;

public class DummyElement implements WebElement, HasIdentity {
public class DummyElement extends RemoteWebElement {
@Override
public void click() {
// dummy
Expand Down Expand Up @@ -100,4 +100,4 @@ public <X> X getScreenshotAs(OutputType<X> outputType) {
public String getId() {
return "123";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import io.appium.java_client.touch.offset.PointOption;
import org.junit.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.HasIdentity;
import org.openqa.selenium.remote.RemoteWebElement;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -60,7 +60,7 @@ public void longPressOptionsShouldBuildProperly() {
.withDuration(ofMillis(1))
.build();
final Map<String, Object> expectedOpts = new HashMap<>();
expectedOpts.put("element", ((HasIdentity) DUMMY_ELEMENT).getId());
expectedOpts.put("element", ((RemoteWebElement) DUMMY_ELEMENT).getId());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

such cast is probably redundant if DUMMY_ELEMENT is already RemoteWebElement

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

DUMMY_ELEMENT is declared as:
private static final WebElement DUMMY_ELEMENT = new DummyElement();

I can change variable type to RemoteWebElement or DummyElement, but I need to revise the logic of other tests, because it could be done intentionally to cover some logic.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

io.appium.java_client.touch.offset.ElementOption#withElement contains type check and type casting logic, so it looks like such declaration is a way to test the method logic.

expectedOpts.put("x", 0);
expectedOpts.put("y", 0);
expectedOpts.put("duration", 1L);
Expand Down