Skip to content
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

Explicit #738

Merged
merged 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,9 @@ public AppiumElementLocator(SearchContext searchContext, By by, boolean shouldCa
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 +89,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 @@ -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;
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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are 32 places that use timeOut vs none with timeout. This PR should keep it consistent, though a later commit to change all usages is probably appropriate.

Copy link
Member

Choose a reason for hiding this comment

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

Why can't we change all the instances?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can/should, just didn't want to deal with those changes in this PR/release. :-)

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

/**
Expand Down Expand Up @@ -144,7 +144,7 @@ protected List<WebElement> proxyForListLocator(ClassLoader ignored,
}

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static boolean checkTimeDifference(long expectedTime, TimeUnit expectedT
"src/test/java/io/appium/java_client/pagefactory_tests/chromedriver");
}
driver = new ChromeDriver();
timeOutDuration = new TimeOutDuration(AppiumFieldDecorator.DEFAULT_IMPLICITLY_WAIT_TIMEOUT,
timeOutDuration = new TimeOutDuration(AppiumFieldDecorator.DEFAULT_TIMEOUT,
AppiumFieldDecorator.DEFAULT_TIMEUNIT);
PageFactory.initElements(new AppiumFieldDecorator(driver, timeOutDuration), this);
}
Expand All @@ -102,10 +102,10 @@ private long getBenchMark(List<WebElement> stubElements) {
}

@Test public void test() {
assertTrue(checkTimeDifference(AppiumFieldDecorator.DEFAULT_IMPLICITLY_WAIT_TIMEOUT,
assertTrue(checkTimeDifference(AppiumFieldDecorator.DEFAULT_TIMEOUT,
AppiumFieldDecorator.DEFAULT_TIMEUNIT, getBenchMark(stubElements)));
System.out.println(
String.valueOf(AppiumFieldDecorator.DEFAULT_IMPLICITLY_WAIT_TIMEOUT) + " "
String.valueOf(AppiumFieldDecorator.DEFAULT_TIMEOUT) + " "
+ AppiumFieldDecorator.DEFAULT_TIMEUNIT.toString() + ": Fine");

timeOutDuration.setTime(15500000, TimeUnit.MICROSECONDS);
Expand All @@ -122,10 +122,10 @@ private long getBenchMark(List<WebElement> stubElements) {
}

@Test public void test2() {
assertTrue(checkTimeDifference(AppiumFieldDecorator.DEFAULT_IMPLICITLY_WAIT_TIMEOUT,
assertTrue(checkTimeDifference(AppiumFieldDecorator.DEFAULT_TIMEOUT,
AppiumFieldDecorator.DEFAULT_TIMEUNIT, getBenchMark(stubElements)));
System.out.println(
String.valueOf(AppiumFieldDecorator.DEFAULT_IMPLICITLY_WAIT_TIMEOUT) + " "
String.valueOf(AppiumFieldDecorator.DEFAULT_TIMEOUT) + " "
+ AppiumFieldDecorator.DEFAULT_TIMEUNIT.toString() + ": Fine");

assertTrue(checkTimeDifference(5, TimeUnit.SECONDS, getBenchMark(stubElements2)));
Expand All @@ -148,7 +148,7 @@ private long getBenchMark(List<WebElement> stubElements) {
long startMark = Calendar.getInstance().getTimeInMillis();
driver.findElements(By.id("FakeId"));
long endMark = Calendar.getInstance().getTimeInMillis();
assertTrue(checkTimeDifference(AppiumFieldDecorator.DEFAULT_IMPLICITLY_WAIT_TIMEOUT,
assertTrue(checkTimeDifference(AppiumFieldDecorator.DEFAULT_TIMEOUT,
AppiumFieldDecorator.DEFAULT_TIMEUNIT, endMark - startMark));
}

Expand Down