-
-
Notifications
You must be signed in to change notification settings - Fork 764
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
The addition to #738 #741
Changes from 3 commits
a6df515
a971cc8
7307777
938ec64
2419dca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
@@ -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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
} | ||
|
||
/** | ||
|
@@ -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) { | ||
|
@@ -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); | ||
} | ||
|
||
/** | ||
|
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why cannot we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this |
||
resultPath = ROOT_TEST_PATH.resolve("chromedriver_linux"); | ||
} | ||
|
||
return resultPath.toFile(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is changed, then the comment should also be changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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\")") | ||
|
@@ -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()); | ||
} | ||
|
||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 withjava.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.
There was a problem hiding this comment.
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