/** * 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); }
/** * 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); }
private WebElement getProxified() { // right now browser.switchTo().activeElement() is an example of a proxified but not wrapped element // we won't rely on that though, because it could easily change, so instead we'll use the proxifier directly (and in // such a way so as to benefit from the fix relevant to the test) GrapheneContextualHandler handler = GrapheneContextualHandler.forTarget(GrapheneContext.lastContext(), browser); WebElement proxy; try { Method findElement = WebDriver.class.getMethod("findElement", By.class); proxy = (WebElement) handler.invoke(browser, findElement, new Object[] { By.id(TEST_ELEMENT_ID) }); } catch (Throwable e) { throw new RuntimeException(e); } // in case you need to reproduce the problem, create the proxy manually: // Class<?>[] interfaces = GrapheneProxyUtil.getInterfaces(getUnwrapped().getClass()); // WebElement proxy = GrapheneProxy.getProxyForTargetWithInterfaces(GrapheneContext.lastContext(), getUnwrapped(), // interfaces); if (!(proxy instanceof GrapheneProxyInstance) || proxy instanceof GrapheneElement) { // it's not right to use asserts here - not the point of the test // also a caller might use @Test(expected = AssertionError.class) throw new RuntimeException( "Not proxified correctly: " + Arrays.toString(GrapheneProxyUtil.getInterfaces(proxy.getClass()))); } return proxy; }