@Test public void generated_webelement_implements_WrapsElement_interface() { TestPage page = new TestPage(); getGrapheneEnricher().enrich(page); assertTrue(page.element instanceof WrapsElement); GrapheneContext.setContextFor(new GrapheneConfiguration(), driver, Default.class); when(driver.findElement(Mockito.any(By.class))).thenReturn(element); WebElement wrappedElement = ((WrapsElement) page.element).getWrappedElement(); GrapheneContext.removeContextFor(Default.class); assertThat(wrappedElement, is(instanceOf(GrapheneElement.class))); assertEquals(element, ((GrapheneElement)wrappedElement).getWrappedElement()); }
@Override public void enrich(final SearchContext searchContext, Object target) { try { List<Field> fields = FindByUtilities.getListOfFieldsAnnotatedWithFindBys(target); for (Field field : fields) { GrapheneContext grapheneContext = searchContext == null ? null : ((GrapheneProxyInstance) searchContext).getGrapheneContext(); final SearchContext localSearchContext; if (grapheneContext == null) { grapheneContext = GrapheneContext.getContextFor(ReflectionHelper.getQualifier(field.getAnnotations())); localSearchContext = grapheneContext.getWebDriver(SearchContext.class); } else { localSearchContext = searchContext; } By by = FindByUtilities.getCorrectBy(field, configuration.get().getDefaultElementLocatingStrategy()); if (field.getType().isAssignableFrom(WebElement.class)) { WebElement element = WebElementUtils.findElementLazily(by, localSearchContext); setValue(field, target, element); } else if (field.getType().isAssignableFrom(List.class) && getListType(field).isAssignableFrom(WebElement.class)) { List<WebElement> elements = WebElementUtils.findElementsLazily(by, localSearchContext); setValue(field, target, elements); } } } catch (ClassNotFoundException e) { throw new IllegalStateException(e.getMessage(), e); } }
WebElementEnricher extends AbstractSearchContextEnricher { @Override public void enrich(final SearchContext searchContext, Object target) { try { List<Field> fields = FindByUtilities.getListOfFieldsAnnotatedWithFindBys(target); for (Field field : fields) { GrapheneContext grapheneContext = searchContext == null ? null : ((GrapheneProxyInstance) searchContext).getGrapheneContext(); final SearchContext localSearchContext; if (grapheneContext == null) { grapheneContext = GrapheneContext.getContextFor(ReflectionHelper.getQualifier(field.getAnnotations())); localSearchContext = grapheneContext.getWebDriver(SearchContext.class); } else { localSearchContext = searchContext; } By by = FindByUtilities.getCorrectBy(field, configuration.get().getDefaultElementLocatingStrategy()); if (field.getType().isAssignableFrom(WebElement.class)) { WebElement element = WebElementUtils.findElementLazily(by, localSearchContext); setValue(field, target, element); } else if (field.getType().isAssignableFrom(List.class) && getListType(field).isAssignableFrom(WebElement.class)) { List<WebElement> elements = WebElementUtils.findElementsLazily(by, localSearchContext); setValue(field, target, elements); } } } catch (ClassNotFoundException e) { throw new IllegalStateException(e.getMessage(), e); } } }
WebElementEnricher extends AbstractSearchContextEnricher { @Override public void enrich(final SearchContext searchContext, Object target) { try { List<Field> fields = FindByUtilities.getListOfFieldsAnnotatedWithFindBys(target); for (Field field : fields) { GrapheneContext grapheneContext = searchContext == null ? null : ((GrapheneProxyInstance) searchContext).getGrapheneContext(); final SearchContext localSearchContext; if (grapheneContext == null) { grapheneContext = GrapheneContext.getContextFor(ReflectionHelper.getQualifier(field.getAnnotations())); localSearchContext = grapheneContext.getWebDriver(SearchContext.class); } else { localSearchContext = searchContext; } By by = FindByUtilities.getCorrectBy(field, configuration.get().getDefaultElementLocatingStrategy()); if (field.getType().isAssignableFrom(WebElement.class)) { WebElement element = WebElementUtils.findElementLazily(by, localSearchContext); setValue(field, target, element); } else if (field.getType().isAssignableFrom(List.class) && getListType(field).isAssignableFrom(WebElement.class)) { List<WebElement> elements = WebElementUtils.findElementsLazily(by, localSearchContext); setValue(field, target, elements); } } } catch (ClassNotFoundException e) { throw new IllegalStateException(e.getMessage(), e); } } WebElementEnricher();  WebElementEnricher(Instance<GrapheneConfiguration> configuration); }
WebElementEnricher extends AbstractSearchContextEnricher { @Override public void enrich(final SearchContext searchContext, Object target) { try { List<Field> fields = FindByUtilities.getListOfFieldsAnnotatedWithFindBys(target); for (Field field : fields) { GrapheneContext grapheneContext = searchContext == null ? null : ((GrapheneProxyInstance) searchContext).getGrapheneContext(); final SearchContext localSearchContext; if (grapheneContext == null) { grapheneContext = GrapheneContext.getContextFor(ReflectionHelper.getQualifier(field.getAnnotations())); localSearchContext = grapheneContext.getWebDriver(SearchContext.class); } else { localSearchContext = searchContext; } By by = FindByUtilities.getCorrectBy(field, configuration.get().getDefaultElementLocatingStrategy()); if (field.getType().isAssignableFrom(WebElement.class)) { WebElement element = WebElementUtils.findElementLazily(by, localSearchContext); setValue(field, target, element); } else if (field.getType().isAssignableFrom(List.class) && getListType(field).isAssignableFrom(WebElement.class)) { List<WebElement> elements = WebElementUtils.findElementsLazily(by, localSearchContext); setValue(field, target, elements); } } } catch (ClassNotFoundException e) { throw new IllegalStateException(e.getMessage(), e); } } WebElementEnricher();  WebElementEnricher(Instance<GrapheneConfiguration> configuration); @Override void enrich(final SearchContext searchContext, Object target); @Override Object[] resolve(SearchContext searchContext, Method method, Object[] resolvedParams); @Override int getPrecedence(); }
WebElementEnricher extends AbstractSearchContextEnricher { @Override public void enrich(final SearchContext searchContext, Object target) { try { List<Field> fields = FindByUtilities.getListOfFieldsAnnotatedWithFindBys(target); for (Field field : fields) { GrapheneContext grapheneContext = searchContext == null ? null : ((GrapheneProxyInstance) searchContext).getGrapheneContext(); final SearchContext localSearchContext; if (grapheneContext == null) { grapheneContext = GrapheneContext.getContextFor(ReflectionHelper.getQualifier(field.getAnnotations())); localSearchContext = grapheneContext.getWebDriver(SearchContext.class); } else { localSearchContext = searchContext; } By by = FindByUtilities.getCorrectBy(field, configuration.get().getDefaultElementLocatingStrategy()); if (field.getType().isAssignableFrom(WebElement.class)) { WebElement element = WebElementUtils.findElementLazily(by, localSearchContext); setValue(field, target, element); } else if (field.getType().isAssignableFrom(List.class) && getListType(field).isAssignableFrom(WebElement.class)) { List<WebElement> elements = WebElementUtils.findElementsLazily(by, localSearchContext); setValue(field, target, elements); } } } catch (ClassNotFoundException e) { throw new IllegalStateException(e.getMessage(), e); } } WebElementEnricher();  WebElementEnricher(Instance<GrapheneConfiguration> configuration); @Override void enrich(final SearchContext searchContext, Object target); @Override Object[] resolve(SearchContext searchContext, Method method, Object[] resolvedParams); @Override int getPrecedence();  }