private void registerInFrameInterceptor(GrapheneProxyInstance proxy, int index, String nameOrId) { if (index != -1) { proxy.registerInterceptor(new InFrameInterceptor(index)); } else { proxy.registerInterceptor(new InFrameInterceptor(nameOrId)); } }
@Override public Object intercept(InvocationContext context) throws Throwable { return elementProxy.unwrap(); }
private GrapheneContext getGrapheneContext(SearchContext searchContext) { if (searchContext instanceof GrapheneProxyInstance) { return ((GrapheneProxyInstance) searchContext).getGrapheneContext(); } else { return GrapheneContext.lastContext(); } } }
return ((GrapheneProxyInstance) target).unwrap(); Object target = getTarget(); if (target instanceof GrapheneProxyInstance) { return ((GrapheneProxyInstance) target).unwrap(); clone = (GrapheneProxyInstance) GrapheneProxy.getProxyForTarget(context, getTarget()); for (Interceptor interceptor : getSortedInterceptorsByPrecedence()) { clone.registerInterceptor(interceptor);
proxy = (GrapheneProxyInstance) ((GrapheneProxyInstance) target).copy(); } else { proxy = (GrapheneProxyInstance) GrapheneProxy.getProxyForTarget(context, target); proxy.registerInterceptor(new Interceptor() { @Override public Object intercept(InvocationContext context) throws Throwable {
public List<Interceptor> unregisterAll() { for(Interceptor interceptor : registeredInterceptors) { ((GrapheneProxyInstance) getWebDriver()).unregisterInterceptor(interceptor); } List<Interceptor> copy = new ArrayList<Interceptor>(registeredInterceptors); registeredInterceptors.clear(); return copy; }
protected GrapheneContext getGrapheneContext(SearchContext searchContext) { if (searchContext instanceof GrapheneProxyInstance) { return ((GrapheneProxyInstance) searchContext).getContext(); } else { return GrapheneContext.lastContext(); } } }
return ((GrapheneProxyInstance) target).unwrap(); Object target = getTarget(); if (target instanceof GrapheneProxyInstance) { return ((GrapheneProxyInstance) target).unwrap(); clone = (GrapheneProxyInstance) GrapheneProxy.getProxyForTarget(context, getTarget()); for (Interceptor interceptor : getSortedInterceptorsByPrecedence()) { clone.registerInterceptor(interceptor);
proxy = (GrapheneProxyInstance) ((GrapheneProxyInstance) target).copy(); } else { proxy = (GrapheneProxyInstance) GrapheneProxy.getProxyForTarget(context, target); proxy.registerInterceptor(new Interceptor() { @Override public Object intercept(InvocationContext context) throws Throwable {
@Override public WebDriver deenhance(WebDriver instance, Class<? extends Annotation> qualifier) { if (GrapheneProxy.isProxyInstance(instance)) { GrapheneProxyInstance proxy = (GrapheneProxyInstance) instance; proxy.unregisterInterceptor(interceptor); } return instance; }
@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 Object intercept(InvocationContext context) throws Throwable { return elementProxy.unwrap(); }
private GrapheneContext getGrapheneContext(SearchContext searchContext) { if (searchContext instanceof GrapheneProxyInstance) { return ((GrapheneProxyInstance) searchContext).getGrapheneContext(); } else { return GrapheneContext.lastContext(); } } }
public List<Interceptor> unregisterAll() { for(Interceptor interceptor : registeredInterceptors) { ((GrapheneProxyInstance) getWebDriver()).unregisterInterceptor(interceptor); } List<Interceptor> copy = new ArrayList<Interceptor>(registeredInterceptors); registeredInterceptors.clear(); return copy; }
private void registerInFrameInterceptor(GrapheneProxyInstance proxy, int index, String nameOrId) { if (index != -1) { proxy.registerInterceptor(new InFrameInterceptor(index)); } else { proxy.registerInterceptor(new InFrameInterceptor(nameOrId)); } }
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; }
protected static GrapheneContext getContext(Object object) { if (!GrapheneProxy.isProxyInstance(object)) { throw new IllegalArgumentException("The parameter [object] has to be instance of " + GrapheneProxyInstance.class.getName() + ", but it is not. The given object is " + object + "."); } return ((GrapheneProxyInstance) object).getGrapheneContext(); }
public void register(Interceptor interceptor) { registeredInterceptors.add(interceptor); ((GrapheneProxyInstance) getWebDriver()).registerInterceptor(interceptor); }
/** * Unwraps the proxy */ @Override public WebDriver deenhance(WebDriver enhancedDriver, Class<? extends Annotation> qualifier) { if (enhancedDriver instanceof GrapheneProxyInstance) { WebDriver driver = ((GrapheneProxyInstance) enhancedDriver).unwrap(); GrapheneContext.removeContextFor(qualifier); return driver; } return enhancedDriver; }
public static JavascriptExecutor getExecutorFromElement(WebElement element) { Preconditions.checkNotNull(element, "The element cannot be null."); if (element instanceof GrapheneProxyInstance) { GrapheneContext context = ((GrapheneProxyInstance) element).getGrapheneContext(); return (JavascriptExecutor) context.getWebDriver(JavascriptExecutor.class); } throw new RuntimeException( "Cannot obtain JavascriptExecutor from element which is not an instance of GrapheneProxyInstance."); }