protected <T> T createWrapper(GrapheneContext grapheneContext, final Class<T> type, final WebElement element) throws Exception { T wrapper = GrapheneProxy.getProxyForHandler( GrapheneContextualHandler.forFuture(grapheneContext, new GrapheneProxy.FutureTarget() { @Override public Object getTarget() { try { return instantiate(type, element); } catch (Exception e) { throw new IllegalStateException("Can't instantiate the " + type, e); } } }), type); return wrapper; }
protected <T> T createWrapper(GrapheneContext grapheneContext, final Class<T> type, final WebElement element) throws Exception { T wrapper = GrapheneProxy.getProxyForHandler( GrapheneContextualHandler.forFuture(grapheneContext, new GrapheneProxy.FutureTarget() { @Override public Object getTarget() { try { return instantiate(type, element); } catch (Exception e) { throw new IllegalStateException("Can't instantiate the " + type, e); } } }), type); return wrapper; }
@SuppressWarnings("unchecked") protected <T> List<T> createWrappers(GrapheneContext grapheneContext, final Class<T> type, final List<WebElement> elements) { List<T> wrapper = GrapheneProxy.getProxyForHandler( GrapheneContextualHandler.forFuture(grapheneContext, new GrapheneProxy.FutureTarget() { @Override public Object getTarget() { try { List<T> target = new ArrayList<T>(); for (WebElement element : elements) { target.add((T) instantiate(type, element)); } return target; } catch (Exception e) { throw new IllegalStateException("Can't instantiate the " + type, e); } } }), List.class); return wrapper; }
@SuppressWarnings("unchecked") protected <T> List<T> createWrappers(GrapheneContext grapheneContext, final Class<T> type, final List<WebElement> elements) { List<T> wrapper = GrapheneProxy.getProxyForHandler( GrapheneContextualHandler.forFuture(grapheneContext, new GrapheneProxy.FutureTarget() { @Override public Object getTarget() { try { List<T> target = new ArrayList<T>(); for (WebElement element : elements) { target.add((T) instantiate(type, element)); } return target; } catch (Exception e) { throw new IllegalStateException("Can't instantiate the " + type, e); } } }), List.class); return wrapper; }
GrapheneProxyHandler handler = GrapheneContextualHandler.forFuture(context, futureTarget); return getProxyForHandler(handler, baseType, additionalInterfaces);
GrapheneProxyHandler handler = GrapheneContextualHandler.forFuture(context, futureTarget); return getProxyForHandler(handler, baseType, additionalInterfaces);
public static List<WebElement> findElementsLazily(final GrapheneContext context, final By by, final GrapheneProxy.FutureTarget searchContextFuture) { List<WebElement> elements = GrapheneProxy.getProxyForHandler(GrapheneContextualHandler.forFuture(context, new GrapheneProxy.FutureTarget() { @Override public Object getTarget() { List<WebElement> result = new ArrayList<WebElement>(); List<WebElement> elements = dropProxyAndFindElements(by, (SearchContext) searchContextFuture.getTarget()); if ((by instanceof ByIdOrName) && (elements.isEmpty())) { LOGGER.log(Level.WARNING, EMPTY_FIND_BY_WARNING); } for (int i = 0; i < elements.size(); i++) { WebElement foundElement = findElementLazily(context, by, searchContextFuture, i); if (foundElement != null) { result.add(foundElement); } } return result; } }), List.class); GrapheneProxyInstance proxy = (GrapheneProxyInstance) elements; proxy.registerInterceptor(new StaleElementInterceptor()); return elements; }
public static List<WebElement> findElementsLazily(final GrapheneContext context, final By by, final GrapheneProxy.FutureTarget searchContextFuture) { List<WebElement> elements = GrapheneProxy.getProxyForHandler(GrapheneContextualHandler.forFuture(context, new GrapheneProxy.FutureTarget() { @Override public Object getTarget() { List<WebElement> result = new ArrayList<WebElement>(); List<WebElement> elements = dropProxyAndFindElements(by, (SearchContext) searchContextFuture.getTarget()); if ((by instanceof ByIdOrName) && (elements.isEmpty())) { LOGGER.log(Level.WARNING, EMPTY_FIND_BY_WARNING); } for (int i = 0; i < elements.size(); i++) { WebElement foundElement = findElementLazily(context, by, searchContextFuture, i); if (foundElement != null) { result.add(foundElement); } } return result; } }), List.class); GrapheneProxyInstance proxy = (GrapheneProxyInstance) elements; proxy.registerInterceptor(new StaleElementInterceptor()); return elements; }
try { context = new LazyContext(qualifier, new BrowserActions(qualifier.getName())); context.handler = GrapheneContextualHandler.forFuture(context, context.getFutureTarget()); GrapheneProxyInstance proxy = (GrapheneProxyInstance) context.getWebDriver(); proxy.registerInterceptor(new SearchContextInterceptor());
try { context = new LazyContext(qualifier, new BrowserActions(qualifier.getName())); context.handler = GrapheneContextualHandler.forFuture(context, context.getFutureTarget()); GrapheneProxyInstance proxy = (GrapheneProxyInstance) context.getWebDriver(); proxy.registerInterceptor(new SearchContextInterceptor());