Skip to content

Commit a9d76f5

Browse files
Merge pull request #469 from TikhomirovSergey/truebit-timeout
Addition to #467
2 parents ef779eb + 90faa5f commit a9d76f5

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class AppiumElementLocator implements CacheableLocator {
4242
final boolean shouldCache;
4343
final By by;
4444
final TimeOutDuration timeOutDuration;
45+
private final TimeOutDuration originalTimeOutDuration;
4546
final WebDriver originalWebDriver;
4647
private final SearchContext searchContext;
4748
private final WaitingFunction waitingFunction;
@@ -56,16 +57,18 @@ class AppiumElementLocator implements CacheableLocator {
5657
* @param by a By locator strategy
5758
* @param shouldCache is the flag that signalizes that elements which
5859
* are found once should be cached
59-
* @param duration is a POJO which contains timeout parameters
60+
* @param duration is a POJO which contains timeout parameters for the element to be searched
61+
* @param originalDuration is a POJO which contains timeout parameters from page object which contains the element
6062
* @param originalWebDriver is an instance of WebDriver that is going to be
6163
* used by a proxied element
6264
*/
6365

6466
public AppiumElementLocator(SearchContext searchContext, By by, boolean shouldCache,
65-
TimeOutDuration duration, WebDriver originalWebDriver) {
67+
TimeOutDuration duration, TimeOutDuration originalDuration, WebDriver originalWebDriver) {
6668
this.searchContext = searchContext;
6769
this.shouldCache = shouldCache;
6870
this.timeOutDuration = duration;
71+
this.originalTimeOutDuration = originalDuration;
6972
this.by = by;
7073
this.originalWebDriver = originalWebDriver;
7174
waitingFunction = new WaitingFunction(this.searchContext);
@@ -89,7 +92,7 @@ private List<WebElement> waitFor() {
8992
} catch (TimeoutException e) {
9093
return new ArrayList<>();
9194
} finally {
92-
changeImplicitlyWaitTimeOut(timeOutDuration.getTime(), timeOutDuration.getTimeUnit());
95+
changeImplicitlyWaitTimeOut(originalTimeOutDuration.getTime(), originalTimeOutDuration.getTimeUnit());
9396
}
9497
}
9598

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public CacheableLocator createLocator(Field field) {
5757
By by = builder.buildBy();
5858
if (by != null) {
5959
return new AppiumElementLocator(searchContext, by, builder.isLookupCached(),
60-
customDuration, originalWebDriver);
60+
customDuration, timeOutDuration, originalWebDriver);
6161
}
6262
return null;
6363
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.junit.Assert;
2424
import org.junit.Before;
2525
import org.junit.Test;
26+
import org.openqa.selenium.By;
2627
import org.openqa.selenium.Platform;
2728
import org.openqa.selenium.WebDriver;
2829
import org.openqa.selenium.WebElement;
@@ -136,7 +137,16 @@ private long getBenchMark(List<WebElement> stubElements) {
136137

137138
checkTimeDifference(5, TimeUnit.SECONDS, getBenchMark(stubElements2));
138139
System.out.println(String.valueOf(5) + " " + TimeUnit.SECONDS.toString() + ": Fine");
140+
}
141+
142+
@Test public void checkThatCustomizedTimeOutDoesNotChangeGeneralValue() {
143+
stubElements2.size(); //time out differs from the general value there
139144

145+
long startMark = Calendar.getInstance().getTimeInMillis();
146+
driver.findElements(By.id("FakeId"));
147+
long endMark = Calendar.getInstance().getTimeInMillis();
148+
checkTimeDifference(AppiumFieldDecorator.DEFAULT_IMPLICITLY_WAIT_TIMEOUT,
149+
AppiumFieldDecorator.DEFAULT_TIMEUNIT, endMark - startMark);
140150
}
141151

142152
}

0 commit comments

Comments
 (0)