@Override public Object decorate(final ClassLoader ignored, final Field field) { if (!isProxyable(field)) { return null; } final ElementLocator locator = new PageElementLocator(webDriver, context, field); if (PageElement.class.isAssignableFrom(field.getType())) { return proxyForLocator(field, locator); } else if (PageElementCollection.class.isAssignableFrom(field.getType())) { return proxyForCollectionLocator(locator); } else { return null; } }
/** * Returns scope represented by this factory. In this case, it is * {@link NestedSelectorScopedElementLocator} constructed out of parent factory and parent field * and selector. */ @Override public ElementLocator getCurrentScope() { return new NestedSelectorScopedElementLocator(searchContext, parentFactory, selector, globalCurrenScope); }
private SearchContext acquireSearchContext(ElementLocatorFactory elementLocatorFactory) { SearchContext searchContext; ElementLocator parentElementLocator = ((ParentElementLocatorProvider) elementLocatorFactory). getCurrentScope(); if (parentElementLocator instanceof SearchContextAwareLocator) { searchContext = ((SearchContextAwareLocator) parentElementLocator).getSearchContext(); } else { searchContext = parentElementLocator.findElement(); } return searchContext; }
private Object proxyForLocator(final Field field, final ElementLocator locator) { final PageElementInterceptor methodInterceptor = new PageElementInterceptor(locator); final Class<?>[] argTypes = new Class<?>[] {}; final Object[] args = new Object[] {}; return getEnhancedProxy(field.getType(), argTypes, args, methodInterceptor); }
@Override public Object decorate(ClassLoader loader, Field field) { if (field.isAnnotationPresent(Root.class)) return null; if (!this.shouldDecorate(field)) return this.nextDecoratorInChain.decorate(loader, field); ElementLocator locator = this.factory.createLocator(field); if (locator == null) return null; return this.decorateField(loader, field, locator); }
private Object decorateField(ClassLoader loader, Field field, ElementLocator locator) { if (this.isDecoratableList(field)) { List<WebElement> webElements = this.proxyForListLocator(loader, locator); Class<?> listType = (Class<?>) ((ParameterizedType) field.getGenericType()) .getActualTypeArguments()[0]; return this.decorate(listType, webElements); } WebElement webElement = this.proxyForLocator(loader, locator); return this.decorate(field.getType(), webElement); }
public LocatingElementListHandler(ElementLocator locator, String name, By by, WebDriver driver) { this.locator = locator; this.name = name; this.by = by; this.webDriver = driver; }
public AbstractUIObjectListHandler(Class<?> clazz, WebDriver webDriver, ElementLocator locator, String name) { this.clazz = clazz; this.webDriver = webDriver; this.locator = locator; this.name = name; }
protected ExtendedWebElement proxyForLocator(ClassLoader loader, Field field, ElementLocator locator) { InvocationHandler handler = new LocatingElementHandler(locator); WebElement proxy = (WebElement) Proxy.newProxyInstance(loader, new Class[] { WebElement.class, WrapsElement.class, Locatable.class }, handler); return new ExtendedWebElement(proxy, field.getName(), field.isAnnotationPresent(FindBy.class) ? new LocalizedAnnotations(field).buildBy() : null, webDriver); }
@SuppressWarnings("unchecked") protected List<ExtendedWebElement> proxyForListLocator(ClassLoader loader, Field field, ElementLocator locator) { InvocationHandler handler = new LocatingElementListHandler(locator, field.getName(), new LocalizedAnnotations(field).buildBy(), webDriver); List<ExtendedWebElement> proxies = (List<ExtendedWebElement>) Proxy.newProxyInstance(loader, new Class[] { List.class }, handler); return proxies; }
@SuppressWarnings("unchecked") protected <T extends AbstractUIObject> List<T> proxyForListUIObjects(ClassLoader loader, Field field, ElementLocator locator) { InvocationHandler handler = new AbstractUIObjectListHandler<T>((Class<?>) getListType(field), webDriver, locator, field.getName()); List<T> proxies = (List<T>) Proxy.newProxyInstance(loader, new Class[] { List.class }, handler); return proxies; }
/** * Returns scope represented by this locator factory. */ @Override public ElementLocator getCurrentScope() { return new WebElementLocator(webElement); }
/** * Return a DefaultElementLocator. */ @Override public ElementLocator createLocator(Field field) { return new DefaultElementLocator(resolveContext(field), field); }
/** * Creates a locator for the given field. */ @Override public ElementLocator createLocator(Field field) { return new SelectorScopedElementLocator(searchContext, selector, field); }
/** * Returns scope represented by this factory. * In this case, it is SelectorElementLocator constructed out of searchContext and selector. */ @Override public ElementLocator getCurrentScope() { return new SelectorElementLocator(searchContext, selector); }
/** * Creates a locator for the given field. */ @Override public ElementLocator createLocator(Field field) { return field.isAnnotationPresent(Global.class) ? new DefaultElementLocator(searchContext, field) : new SelectorScopedElementLocator(searchContext, selector, field); }
@Override public ElementLocator getCurrentScope() { return parentFactory.createLocator(parentField); }
@Override public ElementLocator createLocator(final Field field) { return field.isAnnotationPresent(Global.class) ? new DefaultElementLocator(webDriver, field) : new ScopedElementLocator(parentFactory, parentField, field); }
@Override public ElementLocator createLocator(Field field) { return null; }
@Override public ElementLocator getCurrentScope() { return null; }
public ElementLocator createLocator(Field field) { return new JPageFactoryElementLocator(searchContext, new JPageFactoryAnnotations(field, channel)); }
private WebElement proxyForAnElement(ElementLocator locator) { ElementInterceptor elementInterceptor = new ElementInterceptor(locator, originalDriver); return (WebElement) ProxyFactory.getEnhancedProxy(getTypeForProxy(), elementInterceptor); }
ElementInterceptor(ElementLocator locator, WebDriver driver) { super(locator, driver); }
public InterceptorOfASingleElement(ElementLocator locator, WebDriver driver) { this.locator = locator; this.driver = driver; }
public InterceptorOfAListOfElements(ElementLocator locator) { this.locator = locator; }
ElementListInterceptor(ElementLocator locator) { super(locator); }
@Override public ElementLocator createLocator(Field field) { return new DefaultElementLocator(context, field); }
public ElementCache(final ElementLocator locator, WebElement element) { this.elementLocator = locator; setElement(element); }
public PageElementImpl(final WebDriver webDriver, final ElementLocator elementLocator, final WebElement element) { super(webDriver, elementLocator, element); }
public PageElement parent() { ElementLocator parentLocator = new PageElementLocator(elementLocator.getWebDriver(), By.xpath("..")); return PageElement.makeElement(parentLocator, parentLocator.findElement()); }
@Override public PageElement element(final By by) { ElementLocator childLocator = new PageElementLocator(elementLocator.getWebDriver(), getWrappedElement(), by); return PageElement.makeElement(childLocator, childLocator.findElement()); }
@Override public PageElementCollection all(final By by) { final ElementLocator childLocator = new PageElementLocator(elementLocator.getWebDriver(), getWrappedElement(), by); return makeCollection(childLocator, childLocator.findElements()); }
@Override public PageElement waitUntil(final Condition<WebElement> condition, Timeout timeout) { final ElementLocator filterLocator = new PageElementLocator(elementLocator.getWebDriver(), elementLocator.getSearchContext(), elementLocator.getBy(), elementLocator.getCondition().and(condition), timeout); return PageElement.makeElement(filterLocator, filterLocator.findElement()); }
public WebElementWrapper(final WebDriver webDriver, final ElementLocator elementLocator, final WebElement element) { this.elementLocator = elementLocator; this.cache = new ElementCache(elementLocator, element); this.actions = ActionsFactory.create(webDriver); }
static PageElement makeElement(final ElementLocator elementLocator, final WebElement element) { final PageElement pageElement = new PageElementImpl(elementLocator.getWebDriver(), elementLocator, element); final Table tableElement = new TableElementImpl(elementLocator, element); return new PageElementFacade(pageElement, tableElement); }
public TableElementImpl(final ElementLocator elementLocator, final WebElement element) { this.cache = new ElementCache(elementLocator, element); }
PageElementCollectionInterceptor(final ElementLocator locator) { this.locator = locator; }
private Object proxyForCollectionLocator(final ElementLocator locator) { final PageElementCollectionInterceptor methodInterceptor = new PageElementCollectionInterceptor(locator); final Class<?>[] argTypes = new Class<?>[] { ElementLocator.class, List.class }; final Object[] args = new Object[] { null, null }; return getEnhancedProxy(PageElementCollection.class, argTypes, args, methodInterceptor); }
PageElementInterceptor(final ElementLocator locator) { this.locator = locator; }