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

#764 alternative fix #769

Merged
merged 6 commits into from
Nov 21, 2017
Merged

#764 alternative fix #769

merged 6 commits into from
Nov 21, 2017

Conversation

TikhomirovSergey
Copy link
Contributor

Change list

#764 FIX. This change was made according to the confersation #765

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)

The asking for the current platform was optimized.
The asking for the browser or not was optimized.
Also:
- WidgetListInterceptor was optimized
- some code style improvements
@TikhomirovSergey
Copy link
Contributor Author

@vrunoa You can review it too. It would be cool if you could try to test this change on your environment.

ElementMap element = Optional.ofNullable(mobileElementMap.get(String
.valueOf(hasSessionDetails.getAutomationName()).toLowerCase().trim()))
ElementMap element = Optional.ofNullable(mobileElementMap.get(
String.valueOf(platform).toLowerCase().trim()))
Copy link
Contributor

Choose a reason for hiding this comment

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

does it make any sense to use String.valueOf for values of type String?

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 It may return null value

@@ -67,6 +69,15 @@ public AppiumElementLocator(SearchContext searchContext, By by, boolean shouldCa
this.exceptionMessageIfElementNotFound = "Can't locate an element by this strategy: " + by.toString();
}

private static By getBy(By currentBy, SearchContext currentContent) {
if (!ContentMappedBy.class.isAssignableFrom(currentBy.getClass())) {
return currentBy;
Copy link
Contributor

Choose a reason for hiding this comment

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

it might be easier to understand the code if this condition had an explanation comment

@@ -114,7 +125,8 @@ public WebElement findElement() {
List<WebElement> result;
try {
result = waitFor(() -> {
List<WebElement> list = searchContext.findElements(by);
List<WebElement> list = searchContext
.findElements(getBy(by, searchContext));
if (list.size() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

return list.size() > 0 ? list : null

|| !HasSessionDetails.class.isAssignableFrom(originalDriver.getClass())) {
hasSessionDetails = null;
HasSessionDetails hasSessionDetails = ofNullable(this.originalDriver).map(webDriver -> {
if (!HasSessionDetails.class.isAssignableFrom(originalDriver.getClass())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

originalDriver -> webDriver

@Override public WebElement findElement(SearchContext context) {
return context.findElement(map.get(getCurrentContentType(context)));
return context.findElement(map.get(currentContent));
Copy link
Contributor

Choose a reason for hiding this comment

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

is it ok if map.get returns null in any of these methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not possible. It will use NATIVE_MOBILE_SPECIFIC as it is defined by default or it will use HTML_OR_DEFAULT when there is no SearchContext which also implements ContextArare or HasSessionDetails. Also it will use HTML_OR_DEFAULT when HasSessionDetails.isBrowser returns true or current context != NATIVE_CONTEXT.

Also there is the method

    /**
     * This method sets required content type for the further searching.
     * @param type required content type {@link ContentType}
     * @return self-reference.
     */
    public By useContent(@Nonnull ContentType type) {
        checkNotNull(type);
        currentContent = type;
        return this;
    }

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.

LGTM, just minor comments

@TikhomirovSergey
Copy link
Contributor Author

@mykola-mokhnach I have improved some things that you pointed.
@SrinivasanTarget I am waining for your review.

@appium appium deleted a comment Nov 19, 2017
Copy link
Member

@SrinivasanTarget SrinivasanTarget left a comment

Choose a reason for hiding this comment

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

👍

@SrinivasanTarget
Copy link
Member

LGTM

HasSessionDetails hasSessionDetails = ofNullable(this.originalDriver).map(webDriver -> {
if (!HasSessionDetails.class.isAssignableFrom(originalDriver.getClass())) {
this.webDriver = unpackWebDriverFromSearchContext(context);
HasSessionDetails hasSessionDetails = ofNullable(this.webDriver).map(webDriver -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I meant it's better to use the mapped local variable webDriver -> inside the lambda handler rather than class-level this.originalDriverone.

@TikhomirovSergey
Copy link
Contributor Author

@vrunoa
Also it is interesting to know about the time. Was it increased or reduced with this change on your environment? I will wait for a day or two days.

@appium appium deleted a comment Nov 19, 2017
@vrunoa
Copy link

vrunoa commented Nov 20, 2017

@TikhomirovSergey i'm running tests, i'll get back to you as soon as I have some results.

@TikhomirovSergey
Copy link
Contributor Author

@vrunoa and what the result?

@TikhomirovSergey
Copy link
Contributor Author

ping @vrunoa

@vrunoa
Copy link

vrunoa commented Nov 21, 2017

@TikhomirovSergey sorry for the delay. I'm session a lot less getSession calls and test times got reduced. Lets merge it.

@TikhomirovSergey
Copy link
Contributor Author

TikhomirovSergey commented Nov 21, 2017

@vrunoa How much time was reduced? I will merge it later today

@vrunoa
Copy link

vrunoa commented Nov 21, 2017

@TikhomirovSergey from 2hs to 50minutes approximately.

@SrinivasanTarget
Copy link
Member

2hs to 50minutes approximately

Awesome

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.

None yet

4 participants