use of io.appium.java_client.pagefactory.locator.CacheableLocator in project java-client by appium.
the class AppiumElementLocatorFactory method createLocator.
@Override
@Nullable
public CacheableLocator createLocator(AnnotatedElement annotatedElement) {
TimeOutDuration customDuration;
if (annotatedElement.isAnnotationPresent(WithTimeout.class)) {
WithTimeout withTimeout = annotatedElement.getAnnotation(WithTimeout.class);
customDuration = new TimeOutDuration(withTimeout.time(), withTimeout.unit());
} else {
customDuration = duration;
}
builder.setAnnotated(annotatedElement);
By byResult = builder.buildBy();
return ofNullable(byResult).map(by -> new AppiumElementLocator(searchContext, by, builder.isLookupCached(), customDuration)).orElse(null);
}
use of io.appium.java_client.pagefactory.locator.CacheableLocator in project java-client by appium.
the class AppiumFieldDecorator method decorateWidget.
@SuppressWarnings("unchecked")
private Object decorateWidget(Field field) {
Class<?> type = field.getType();
if (!Widget.class.isAssignableFrom(type) && !List.class.isAssignableFrom(type)) {
return null;
}
Class<? extends Widget> widgetType;
boolean isAlist = false;
if (List.class.isAssignableFrom(type)) {
isAlist = true;
Type genericType = field.getGenericType();
if (!(genericType instanceof ParameterizedType)) {
return null;
}
Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0];
if (ParameterizedType.class.isAssignableFrom(listType.getClass())) {
listType = ((ParameterizedType) listType).getRawType();
}
if (listType instanceof Class) {
if (!Widget.class.isAssignableFrom((Class) listType)) {
return null;
}
widgetType = Class.class.cast(listType);
} else {
return null;
}
} else {
widgetType = (Class<? extends Widget>) field.getType();
}
CacheableLocator locator = widgetLocatorFactory.createLocator(field);
Map<ContentType, Constructor<? extends Widget>> map = OverrideWidgetReader.read(widgetType, field, platform, automation);
if (isAlist) {
return getEnhancedProxy(ArrayList.class, new WidgetListInterceptor(locator, webDriver, map, widgetType, duration));
}
Constructor<? extends Widget> constructor = WidgetConstructorUtil.findConvenientConstructor(widgetType);
return getEnhancedProxy(widgetType, new Class[] { constructor.getParameterTypes()[0] }, new Object[] { proxyForAnElement(locator) }, new WidgetInterceptor(locator, webDriver, null, map, duration));
}
use of io.appium.java_client.pagefactory.locator.CacheableLocator in project java-client by appium.
the class WidgetListInterceptor method getObject.
@Override
protected Object getObject(List<WebElement> elements, Method method, Object[] args) throws Throwable {
if (cachedElements == null || (locator != null && !((CacheableLocator) locator).isLookUpCached())) {
cachedElements = elements;
cachedWidgets.clear();
ContentType type = null;
for (WebElement element : cachedElements) {
type = ofNullable(type).orElseGet(() -> getCurrentContentType(element));
Class<?>[] params = new Class<?>[] { instantiationMap.get(type).getParameterTypes()[0] };
cachedWidgets.add(ProxyFactory.getEnhancedProxy(declaredType, params, new Object[] { element }, new WidgetInterceptor(null, driver, element, instantiationMap, duration)));
}
}
try {
return method.invoke(cachedWidgets, args);
} catch (Throwable t) {
throw extractReadableException(t);
}
}
Aggregations