protected final <T> List<T> createPageFragmentList(final Class<T> clazz, final SearchContext searchContext, final By rootBy) { GrapheneContext grapheneContext = ((GrapheneProxyInstance) searchContext).getGrapheneContext(); List<T> result = GrapheneProxy.getProxyForFutureTarget(grapheneContext, new FutureTarget() { @Override public Object getTarget() { List<WebElement> elements = searchContext.findElements(rootBy); List<T> fragments = new ArrayList<T>(); for (int i = 0; i < elements.size(); i++) { fragments.add(createPageFragment(clazz, WebElementUtils.findElementLazily(rootBy, searchContext, i))); } return fragments; } }, List.class); return result; }
protected final <T> List<T> createPageFragmentList(final Class<T> clazz, final SearchContext searchContext, final By rootBy) { GrapheneContext grapheneContext = ((GrapheneProxyInstance) searchContext).getGrapheneContext(); List<T> result = GrapheneProxy.getProxyForFutureTarget(grapheneContext, new FutureTarget() { @Override public Object getTarget() { List<WebElement> elements = searchContext.findElements(rootBy); List<T> fragments = new ArrayList<T>(); for (int i = 0; i < elements.size(); i++) { fragments.add(createPageFragment(clazz, WebElementUtils.findElementLazily(rootBy, searchContext, i))); } return fragments; } }, List.class); return result; }
if (baseType != null && !baseType.isInterface() && Modifier.isFinal(baseType.getModifiers())) { if (additionalInterfaces.length > 0) { return GrapheneProxy.getProxyForFutureTarget(context, futureTarget, additionalInterfaces[0], additionalInterfaces); } else { throw new IllegalStateException("Can't create a proxy for " + baseType
if (baseType != null && !baseType.isInterface() && Modifier.isFinal(baseType.getModifiers())) { if (additionalInterfaces.length > 0) { return GrapheneProxy.getProxyForFutureTarget(context, futureTarget, additionalInterfaces[0], additionalInterfaces); } else { throw new IllegalStateException("Can't create a proxy for " + baseType
protected static WebElement findElement(GrapheneContext context, final GrapheneProxy.FutureTarget target) { final WebElement element = GrapheneProxy.getProxyForFutureTarget(context, target, WebElement.class, INTERFACES_PROXY_SHOULD_IMPLEMENT); final GrapheneProxyInstance elementProxy = (GrapheneProxyInstance) element; InterceptorBuilder b = new InterceptorBuilder(); b.interceptInvocation(WrapsElement.class, new WrapsElementInterceptor(elementProxy)).getWrappedElement(); elementProxy.registerInterceptor(b.build()); elementProxy.registerInterceptor(new StaleElementInterceptor()); elementProxy.registerInterceptor(new SearchContextInterceptor()); return element; }
protected static WebElement findElement(GrapheneContext context, final GrapheneProxy.FutureTarget target) { final WebElement element = GrapheneProxy.getProxyForFutureTarget(context, target, WebElement.class, INTERFACES_PROXY_SHOULD_IMPLEMENT); final GrapheneProxyInstance elementProxy = (GrapheneProxyInstance) element; InterceptorBuilder b = new InterceptorBuilder(); b.interceptInvocation(WrapsElement.class, new WrapsElementInterceptor(elementProxy)).getWrappedElement(); elementProxy.registerInterceptor(b.build()); elementProxy.registerInterceptor(new StaleElementInterceptor()); elementProxy.registerInterceptor(new SearchContextInterceptor()); return element; }
@Test public void when_proxy_is_created_then_no_constructor_is_called() { // having FutureTarget target = new FutureTarget() { @Override public Object getTarget() { throw new ExpectedException(); } }; // when TestingDriver driver = GrapheneProxy.<TestingDriver>getProxyForFutureTarget(null, target, TestingDriver.class); try { driver.quit(); fail("exception should be thrown because of FutureTarget definition"); } catch (ExpectedException e) { // expected } // verify assertFalse(TestingDriver.contructorInvoked); }