@Override public WebDriver enhance(final WebDriver instance, Class<? extends Annotation> qualifier) { if (GrapheneProxy.isProxyInstance(instance)) { GrapheneProxyInstance proxy = (GrapheneProxyInstance) instance; proxy.registerInterceptor(interceptor); } return instance; }
@Override public WebDriver deenhance(WebDriver instance, Class<? extends Annotation> qualifier) { if (GrapheneProxy.isProxyInstance(instance)) { GrapheneProxyInstance proxy = (GrapheneProxyInstance) instance; proxy.unregisterInterceptor(interceptor); } return instance; }
/** * Delegates to {@link #invoke(Object, Method, Object[])} to serve as {@link MethodInterceptor}. */ @Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { return invoke(obj, method, args); }
public static WebElement unwrap(WebElement element) { Preconditions.checkNotNull(element, "The element cannot be null."); WebElement result = element; while (GrapheneProxy.isProxyInstance(result)) { result = ((GrapheneProxyInstance) result).unwrap(); } return result; }
@Override public Object intercept(InvocationContext context) throws Throwable { invoked = true; return context.invoke(); } @Override
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; }
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; }
@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()); } };
/** * Computes the target for invocation - if future target is provided, it will be returned, othewise the target instance will * be returned. * * @return the real target for invocation */ protected Object getTarget() { return (future == null) ? target : future.getTarget(); }
/** * Returns invocation handler which wraps the given target instance. * * @param target the target of invocation * @return invocation handler which wraps the given target instance */ public static GrapheneContextualHandler forTarget(GrapheneContext context, Object target) { GrapheneContextualHandler handler = new GrapheneContextualHandler(context, target); return handler; }
@Override public Object getTarget() { return context.getProxy(); } };
/** * Delegates to {@link #invoke(Object, Method, Object[])} to serve as {@link MethodInterceptor}. */ @Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { return invoke(obj, method, args); }
public Object intercept(InvocationContext context) throws Throwable { interceptor_registered_before_test_invoked = true; return context.invoke(); } public int getPrecedence() {
/** * Computes the target for invocation - if future target is provided, it will be returned, othewise the target instance will * be returned. * * @return the real target for invocation */ protected Object getTarget() { return (future == null) ? target : future.getTarget(); }
/** * Delegates to {@link #invoke(Object, Method, Object[])} to serve as {@link MethodInterceptor}. */ @Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { return invoke(obj, method, args); }
/** * Returns invocation handler which wraps the target for future computation. * * @param future the future target * @return invocation handler which wraps the target for future computation */ public static GrapheneContextualHandler forFuture(GrapheneContext context, FutureTarget future) { GrapheneContextualHandler handler = new GrapheneContextualHandler(context, future); return handler; }
@Override public Object getTarget() { return context.getProxy(); } };
/** * Delegates to {@link #invoke(Object, Method, Object[])} to serve as {@link MethodInterceptor}. */ @Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { return invoke(obj, method, args); }
/** * Returns invocation handler which wraps the given target instance. * * @param target the target of invocation * @return invocation handler which wraps the given target instance */ public static GrapheneContextualHandler forTarget(GrapheneContext context, Object target) { GrapheneContextualHandler handler = new GrapheneContextualHandler(context, target); return handler; }
/** * Returns invocation handler which wraps the target for future computation. * * @param future the future target * @return invocation handler which wraps the target for future computation */ public static GrapheneContextualHandler forFuture(GrapheneContext context, FutureTarget future) { GrapheneContextualHandler handler = new GrapheneContextualHandler(context, future); return handler; }