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

The addition to #738 #741

Merged
merged 5 commits into from
Oct 2, 2017
Merged

The addition to #738 #741

merged 5 commits into from
Oct 2, 2017

Conversation

TikhomirovSergey
Copy link
Contributor

@TikhomirovSergey TikhomirovSergey commented Sep 29, 2017

Change list

The addition to #738

Types of changes

  • No changes in production code.
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Details

The addition to #738

  • following dependencies were updated:
    org.seleniumhq.selenium:selenium-java to 3.6.0
    com.google.code.gson:gson to 2.8.2
    org.springframework:spring-context to 5.0.0.RELEASE
    org.aspectj:aspectjweaver to 1.8.11

  • unused parameters and fields were removed from AppiumElementLocator,
    AppiumElementLocatorFactory

  • some test improving

titusfortner and others added 3 commits September 27, 2017 19:15
- following dependencies were updated:
  `org.seleniumhq.selenium:selenium-java` to 3.6.0
  `com.google.code.gson:gson` to 2.8.2
  `org.springframework:spring-context` to 5.0.0.RELEASE
  `org.aspectj:aspectjweaver` to 1.8.11

 - unused parameters and fields were removed from AppiumElementLocator,
 AppiumElementLocatorFactory

 - some test improving
@TikhomirovSergey TikhomirovSergey self-assigned this Sep 29, 2017
@TikhomirovSergey TikhomirovSergey changed the title Titusfortner explicit The addition to #738 Sep 29, 2017
Copy link
Contributor

@titusfortner titusfortner left a comment

Choose a reason for hiding this comment

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

This looks like it incorporates the stuff I care about. I just have that one comment that doesn't affect the functionality. :)

@@ -44,7 +44,7 @@
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'
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is changed, then the comment should also be changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. I will improve it a bit later.

*/

public AppiumElementLocator(SearchContext searchContext, By by, boolean shouldCache,
TimeOutDuration duration, TimeOutDuration originalDuration, WebDriver originalWebDriver) {
TimeOutDuration duration, TimeOutDuration originalDuration) {
Copy link
Contributor

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?

Copy link
Contributor Author

@TikhomirovSergey TikhomirovSergey Sep 30, 2017

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 with java.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.

Copy link
Contributor

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

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as above

@@ -62,7 +62,7 @@
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;
Copy link
Contributor

Choose a reason for hiding this comment

The 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

@@ -73,9 +73,9 @@
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

import java.nio.file.Path;

public final class ChromeDriverPathUtil {
private static final Path ROOT_TEST_PATH = getDefault().getPath("src")
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

Path resultPath;
Platform current = getCurrent();

if (current.is(WINDOWS)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why cannot we use switch () case ...: return here? this will allow to get rid of many temporary variables

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mykola-mokhnach

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)

Copy link
Contributor

Choose a reason for hiding this comment

The 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

import java.util.List;
import java.util.concurrent.TimeUnit;

public class TimeOutTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

TimeoutTest


public class TimeOutTest {

private static final long ACCEPTABLE_DELTA_MILLS = 1500;
Copy link
Contributor

Choose a reason for hiding this comment

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

->Duration


private TimeOutDuration timeOutDuration;

private static long getBenchMark(List<WebElement> stubElements) {
Copy link
Contributor

Choose a reason for hiding this comment

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

getBenchmark

private TimeOutDuration timeOutDuration;

private static long getBenchMark(List<WebElement> stubElements) {
long startMark = Calendar.getInstance().getTimeInMillis();
Copy link
Contributor

Choose a reason for hiding this comment

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

I usually use System.nanoTime() for such purpose or System.currentTimeMillis() if we don't need nano-preciseness. Calendar class has different purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes :) it was taken from the old code of the test. will improve it.


private TimeOutDuration timeOutDuration;

private static long getBenchMark(List<WebElement> stubElements) {
Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Sep 30, 2017

Choose a reason for hiding this comment

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

One can make this method more generic by providing a lambda function to benchmark:

private static Duration getBenchmark(Runnable dstFunc) {
  final long startTime = System.currentTimeMillis();
  dstFunc.run();
  return Duration.ofMillis(System.currentTimeMillis() - startTime);
}

@TikhomirovSergey
Copy link
Contributor Author

@mykola-mokhnach This PR was updated.
Also I have opened the #742. It is going to be closed in the next release.

@appium appium deleted a comment Sep 30, 2017

return ofNullable(byResult)
.map(by -> new AppiumElementLocator(searchContext, by, builder.isLookupCached(), customDuration))
.orElse(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

The method can be marked as Nullable

return ROOT_TEST_PATH.resolve("chromedriver.exe").toFile();
} else if (current.is(MAC)) {
return ROOT_TEST_PATH.resolve("chromedriver_mac").toFile();
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

this else is not needed


@Test public void defaultTimeOutTest() {
assertThat(format(MESSAGE, DEFAULT_TIMEOUT, DEFAULT_TIMEUNIT),
abs(getExpectedMillis(DEFAULT_TIMEOUT, DEFAULT_TIMEUNIT) - getBenchmark(() -> stubElements.size())),
Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Oct 1, 2017

Choose a reason for hiding this comment

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

I assume the whole formula can be extracted into a separate method, for example:

private static long getPerformanceDiff(long expectedMs, Runnable m) {
   return abs(expectedMs  - getBenchmark(m));
}


public class TimeoutTest {

private static final long ACCEPTABLE_TIME_DIFF = 1500;
Copy link
Contributor

Choose a reason for hiding this comment

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

It is a good practice to explicitly mention measurement unit in var name in case it is of primitive data type (e.g. _MS, _SEC)

Copy link
Contributor

@mykola-mokhnach mykola-mokhnach left a comment

Choose a reason for hiding this comment

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

minor comments only

@appium appium deleted a comment Oct 1, 2017
@mykola-mokhnach
Copy link
Contributor

Replacing DIFF with DELTA might be easier to read. Otherwise LGTM

@TikhomirovSergey TikhomirovSergey merged commit 3229163 into appium:master Oct 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants