/** * Returns the instance of proxy to thread local context of configuration * * @return the instance of proxy to thread local context of configuration */ public static FundamentalTestConfiguration getProxy() { return GrapheneProxy.getProxyForHandler(new GrapheneProxyHandler(TARGET) { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return method.invoke(TARGET.getTarget(), args); } }, FundamentalTestConfiguration.class); }
/** * Returns the instance of proxy to thread local context of configuration * * @return the instance of proxy to thread local context of configuration */ public static RichFacesPageFragmentsConfiguration getProxy() { return GrapheneProxy.getProxyForHandler(new GrapheneProxyHandler(TARGET) { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return method.invoke(TARGET.getTarget(), args); } }, RichFacesPageFragmentsConfiguration.class); }
protected <BASE> BASE base(final Annotation[] annotations) { final GrapheneProxy.FutureTarget futureTarget = new GrapheneProxy.FutureTarget() { @Override public Object getTarget() { GrapheneContext context = GrapheneContext.getContextFor(ReflectionHelper.getQualifier(annotations)); return context.getWebDriver(mediatorType); } }; GrapheneProxyHandler mediatorHandler = new GrapheneProxyHandler(futureTarget) { @Override public Object invoke(Object proxy, final Method mediatorMethod, final Object[] mediatorArgs) throws Throwable { GrapheneProxyHandler handler = new GrapheneProxyHandler(futureTarget) { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object mediatorObject = mediatorMethod.invoke(getTarget(), mediatorArgs); return method.invoke(mediatorObject, args); } }; return GrapheneProxy.getProxyForHandler(handler, mediatorMethod.getReturnType()); } }; return (BASE) GrapheneProxy.getProxyForHandler(mediatorHandler, WebDriver.class, mediatorType); }
protected <BASE> BASE base(final Annotation[] annotations) { final GrapheneProxy.FutureTarget futureTarget = new GrapheneProxy.FutureTarget() { @Override public Object getTarget() { GrapheneContext context = GrapheneContext.getContextFor(ReflectionHelper.getQualifier(annotations)); return context.getWebDriver(mediatorType); } }; GrapheneProxyHandler mediatorHandler = new GrapheneProxyHandler(futureTarget) { @Override public Object invoke(Object proxy, final Method mediatorMethod, final Object[] mediatorArgs) throws Throwable { GrapheneProxyHandler handler = new GrapheneProxyHandler(futureTarget) { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object mediatorObject = mediatorMethod.invoke(getTarget(), mediatorArgs); return method.invoke(mediatorObject, args); } }; return GrapheneProxy.getProxyForHandler(handler, mediatorMethod.getReturnType()); } }; return (BASE) GrapheneProxy.getProxyForHandler(mediatorHandler, WebDriver.class, mediatorType); }
@Override public Object invoke(Object proxy, final Method mediatorMethod, final Object[] mediatorArgs) throws Throwable { GrapheneProxyHandler handler = new GrapheneProxyHandler(futureTarget) { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object mediatorObject = mediatorMethod.invoke(getTarget(), mediatorArgs); return method.invoke(mediatorObject, args); } }; return GrapheneProxy.getProxyForHandler(handler, mediatorMethod.getReturnType()); } };
@Override public Object invoke(Object proxy, final Method mediatorMethod, final Object[] mediatorArgs) throws Throwable { GrapheneProxyHandler handler = new GrapheneProxyHandler(futureTarget) { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object mediatorObject = mediatorMethod.invoke(getTarget(), mediatorArgs); return method.invoke(mediatorObject, args); } }; return GrapheneProxy.getProxyForHandler(handler, mediatorMethod.getReturnType()); } };
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; }
@Override public WebDriver getWebDriver(Class<?>... interfaces) { GrapheneContext context = getContext(false); if (context == null) { return GrapheneProxy.getProxyForHandler(handler, WebDriver.class, interfaces); } else if (GrapheneProxyUtil.isProxy(context.getWebDriver())) { Class<?> superclass = context.getWebDriver().getClass().getSuperclass(); if (superclass != null && !GrapheneProxyUtil.isProxy(superclass) && WebDriver.class.isAssignableFrom(superclass)) { return GrapheneProxy.getProxyForHandler(handler, context.getWebDriver().getClass().getSuperclass(), interfaces); } else { return GrapheneProxy.getProxyForHandler(handler, WebDriver.class, interfaces); } } else { return GrapheneProxy.getProxyForHandler(handler, context.getWebDriver().getClass(), interfaces); } }
@Override public WebDriver getWebDriver(Class<?>... interfaces) { GrapheneContext context = getContext(false); if (context == null) { return GrapheneProxy.getProxyForHandler(handler, WebDriver.class, interfaces); } else if (GrapheneProxyUtil.isProxy(context.getWebDriver())) { Class<?> superclass = context.getWebDriver().getClass().getSuperclass(); if (superclass != null && !GrapheneProxyUtil.isProxy(superclass) && WebDriver.class.isAssignableFrom(superclass)) { return GrapheneProxy.getProxyForHandler(handler, context.getWebDriver().getClass().getSuperclass(), interfaces); } else { return GrapheneProxy.getProxyForHandler(handler, WebDriver.class, interfaces); } } else { return GrapheneProxy.getProxyForHandler(handler, context.getWebDriver().getClass(), interfaces); } }
return getProxyForHandler(handler, baseType, additionalInterfaces);
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; }
public static <P> P setupPage(GrapheneContext context, SearchContext searchContext, Class<?> pageClass) throws Exception{ P page = (P) instantiate(pageClass); P proxy = GrapheneProxy.getProxyForHandler(GrapheneContextualHandler.forTarget(context, page), pageClass); enrichRecursively(searchContext, page); enrichRecursively(searchContext, proxy); // because of possibility of direct access to attributes from test class return proxy; }
public static <P> P setupPage(GrapheneContext context, SearchContext searchContext, Class<?> pageClass) throws Exception{ P page = (P) instantiate(pageClass); P proxy = GrapheneProxy.getProxyForHandler(GrapheneContextualHandler.forTarget(context, page), pageClass); enrichRecursively(searchContext, page); enrichRecursively(searchContext, proxy); // because of possibility of direct access to attributes from test class return proxy; }
T proxy = GrapheneProxy.getProxyForHandler(GrapheneContextualHandler.forTarget(grapheneContext, pageFragment), clazz);
T proxy = GrapheneProxy.getProxyForHandler(GrapheneContextualHandler.forTarget(grapheneContext, pageFragment), clazz);