Repository: appium/java-client
Issue: page object pattern, field with "@WithTimeout" would change the global implicit wait time

## Description

page object pattern, field with "@WithTimeout" would change the global implicit wait time
## Environment

Always exists.  see code analysis below
## Details

in method [AppiumElementLocatorFactory#createLocator](https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocatorFactory.java#L47):
- if the page object field contains annoation `WithTimeout`, it would create a new `TimeOutDuration` instance.
- This instance would be passed to `AppiumElementLocator`.
- When element tries to find the element. It would invoke method [AppiumElementLocator#waitFor](https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java#L92). See the line in `finally` block. it would change the global implicit wait time using the `WithTimeout` value.

So this would make the page object and global appium driver implicit wait both change to that value. It would mess the implicit timeout when there are many `WithTimeout` elements in page objects that contains `driver.findElement` methods.

There is no getter for implicit wait by design. so it is not easy to fix this.

Solution suggestion: 
IMO changing constructors that also passes original timeout duration as argument, in finally block it would set back to original timeout duration.


Changed files:
src/main/java/io/appium/java_client/pagefactory/AppiumElementLocatorFactory.java, src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java

diff --git a/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java b/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java
index 5ccfdb09..eb11f441 100644
--- a/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java
+++ b/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java
@@ -42,6 +42,7 @@ class AppiumElementLocator implements CacheableLocator {
     final boolean shouldCache;
     final By by;
     final TimeOutDuration timeOutDuration;
+    private final TimeOutDuration originalTimeOutDuration;
     final WebDriver originalWebDriver;
     private final SearchContext searchContext;
     private final WaitingFunction waitingFunction;
@@ -56,16 +57,18 @@ class AppiumElementLocator implements CacheableLocator {
      * @param by                a By locator strategy
      * @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
+     * @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, WebDriver originalWebDriver) {
+        TimeOutDuration duration, TimeOutDuration originalDuration, WebDriver originalWebDriver) {
         this.searchContext = searchContext;
         this.shouldCache = shouldCache;
         this.timeOutDuration = duration;
+        this.originalTimeOutDuration = originalDuration;
         this.by = by;
         this.originalWebDriver = originalWebDriver;
         waitingFunction = new WaitingFunction(this.searchContext);
@@ -89,7 +92,7 @@ class AppiumElementLocator implements CacheableLocator {
         } catch (TimeoutException e) {
             return new ArrayList<>();
         } finally {
-            changeImplicitlyWaitTimeOut(timeOutDuration.getTime(), timeOutDuration.getTimeUnit());
+            changeImplicitlyWaitTimeOut(originalTimeOutDuration.getTime(), originalTimeOutDuration.getTimeUnit());
         }
     }
 
diff --git a/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocatorFactory.java b/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocatorFactory.java
index fa13938e..1b9c8ebe 100644
--- a/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocatorFactory.java
+++ b/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocatorFactory.java
@@ -57,7 +57,7 @@ class AppiumElementLocatorFactory implements CacheableElementLocatorFactory {
         By by = builder.buildBy();
         if (by != null) {
             return new AppiumElementLocator(searchContext, by, builder.isLookupCached(),
-                    customDuration, originalWebDriver);
+                    customDuration, timeOutDuration, originalWebDriver);
         }
         return null;
     }