Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.appium.java_client.pagefactory.bys.builder.AppiumByBuilder;
import io.appium.java_client.pagefactory.locator.CacheableElementLocatorFactory;
import io.appium.java_client.pagefactory.locator.CacheableLocator;
import org.openqa.selenium.By;
import org.openqa.selenium.SearchContext;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -90,12 +89,18 @@ public CacheableLocator createLocator(AnnotatedElement annotatedElement) {
customDuration = duration;
}
builder.setAnnotated(annotatedElement);
By byResult = builder.buildBy();
return ofNullable(byResult)
.map(by -> searchContextReference != null
? new AppiumElementLocator(searchContextReference, by, builder.isLookupCached(), customDuration)
: new AppiumElementLocator(searchContext, by, builder.isLookupCached(), customDuration)
)
.orElse(null);
try {
return ofNullable(builder.buildBy())
.map(by -> {
var isLookupCached = builder.isLookupCached();
return searchContextReference != null
? new AppiumElementLocator(searchContextReference, by, isLookupCached, customDuration)
: new AppiumElementLocator(searchContext, by, isLookupCached, customDuration);
})
.orElse(null);
} finally {
// unleak element reference after the locator is built
builder.setAnnotated(null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static Class<?> getClassFromAListField(Field field) {
@SuppressWarnings("unchecked")
private By getByFromDeclaredClass(WhatIsNeeded whatIsNeeded) {
AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();
Field field = Field.class.cast(annotatedElement);
Field field = (Field) annotatedElement;
Class<?> declaredClass;

By result = null;
Expand Down