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 WebDriver enhance(final WebDriver instance, Class<? extends Annotation> qualifier) { if (GrapheneProxy.isProxyInstance(instance)) { GrapheneProxyInstance proxy = (GrapheneProxyInstance) instance; proxy.registerInterceptor(interceptor); } return instance; }
public void register(Interceptor interceptor) { registeredInterceptors.add(interceptor); ((GrapheneProxyInstance) getWebDriver()).registerInterceptor(interceptor); }
private void registerInFrameInterceptor(GrapheneProxyInstance proxy, int index, String nameOrId) { if (index != -1) { proxy.registerInterceptor(new InFrameInterceptor(index)); } else { proxy.registerInterceptor(new InFrameInterceptor(nameOrId)); } }
public void register(Interceptor interceptor) { registeredInterceptors.add(interceptor); ((GrapheneProxyInstance) getWebDriver()).registerInterceptor(interceptor); }
protected static WebElement findElement(GrapheneContext context, final GrapheneProxy.FutureTarget target) { final WebElement element = GrapheneProxy.getProxyForFutureTarget(context, target, WebElement.class, INTERFACES_PROXY_SHOULD_IMPLEMENT); final GrapheneProxyInstance elementProxy = (GrapheneProxyInstance) element; InterceptorBuilder b = new InterceptorBuilder(); b.interceptInvocation(WrapsElement.class, new WrapsElementInterceptor(elementProxy)).getWrappedElement(); elementProxy.registerInterceptor(b.build()); elementProxy.registerInterceptor(new StaleElementInterceptor()); elementProxy.registerInterceptor(new SearchContextInterceptor()); return element; }
protected static WebElement findElement(GrapheneContext context, final GrapheneProxy.FutureTarget target) { final WebElement element = GrapheneProxy.getProxyForFutureTarget(context, target, WebElement.class, INTERFACES_PROXY_SHOULD_IMPLEMENT); final GrapheneProxyInstance elementProxy = (GrapheneProxyInstance) element; InterceptorBuilder b = new InterceptorBuilder(); b.interceptInvocation(WrapsElement.class, new WrapsElementInterceptor(elementProxy)).getWrappedElement(); elementProxy.registerInterceptor(b.build()); elementProxy.registerInterceptor(new StaleElementInterceptor()); elementProxy.registerInterceptor(new SearchContextInterceptor()); return element; }
@Before public void register_interceptor_before_test() { ((GrapheneProxyInstance) browser).registerInterceptor(new Interceptor() { public Object intercept(InvocationContext context) throws Throwable { interceptor_registered_before_test_invoked = true; return context.invoke(); } public int getPrecedence() { return 0; } }); }
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; }
context.handler = GrapheneContextualHandler.forFuture(context, context.getFutureTarget()); GrapheneProxyInstance proxy = (GrapheneProxyInstance) context.getWebDriver(); proxy.registerInterceptor(new SearchContextInterceptor()); proxy.registerInterceptor(new StaleElementInterceptor()); context.installatorProvider = new RemotePageExtensionInstallatorProvider(context.registry, (JavascriptExecutor) context.getWebDriver(JavascriptExecutor.class)); final GrapheneContext finalContext = context;
context.handler = GrapheneContextualHandler.forFuture(context, context.getFutureTarget()); GrapheneProxyInstance proxy = (GrapheneProxyInstance) context.getWebDriver(); proxy.registerInterceptor(new SearchContextInterceptor()); proxy.registerInterceptor(new StaleElementInterceptor()); context.installatorProvider = new RemotePageExtensionInstallatorProvider(context.registry, (JavascriptExecutor) context.getWebDriver(JavascriptExecutor.class)); final GrapheneContext finalContext = context;
@Test public void testContextVsDrone() { ((GrapheneProxyInstance) browser1).registerInterceptor(createInterceptor(counter1)); ((GrapheneProxyInstance) browser2).registerInterceptor(createInterceptor(counter2)); ((GrapheneProxyInstance) browserDefault).registerInterceptor(createInterceptor(counterDefault)); context1.getWebDriver().getTitle(); context2.getWebDriver().getTitle(); contextDefault.getWebDriver().getTitle(); Assert.assertEquals(1, counter1.get()); Assert.assertEquals(1, counter2.get()); Assert.assertEquals(1, counterDefault.get()); }
@Test public void test() throws Throwable { InterceptorBuilder builder = new InterceptorBuilder(); builder.interceptInvocation(WebDriver.class, interceptor1).findElement(Interceptors.any(By.class)); builder.interceptInvocation(WebDriver.class, interceptor2).findElement(Interceptors.any(By.class)); Interceptor builtInterceptor = builder.build(); WebDriver driverProxy = GrapheneProxy.getProxyForTargetWithInterfaces(context, driver, WebDriver.class); GrapheneProxyInstance proxy = (GrapheneProxyInstance) driverProxy; proxy.registerInterceptor(builtInterceptor); driverProxy.findElement(by); Mockito.inOrder(interceptor1, interceptor2); verify(interceptor1).intercept(Mockito.any(InvocationContext.class)); verify(interceptor2).intercept(Mockito.any(InvocationContext.class)); } }
.getWrappedElement(); elementProxy.registerInterceptor(b.build());
@Test @InSequence(1) public void interceptor_can_be_registered_in_test_itself() { ((GrapheneProxyInstance) browser).registerInterceptor(new Interceptor() { @Override public Object intercept(InvocationContext context) throws Throwable { invoked = true; return context.invoke(); } @Override public int getPrecedence() { return 0; } }); assertFalse(invoked); browser.get("about:blank"); assertTrue(invoked); }
@Override public Object intercept(InvocationContext context) throws Throwable { WebDriver browser = context.getGrapheneContext().getWebDriver(); if (indexOfFrame != -1) { browser.switchTo().frame(indexOfFrame); } else if (nameOrIdOfFrame != null) { browser.switchTo().frame(nameOrIdOfFrame); } Object result = null; try { result = context.invoke(); } finally { browser.switchTo().defaultContent(); } if (result instanceof GrapheneProxyInstance) { ((GrapheneProxyInstance) result).registerInterceptor(this); } return result; }
@Test public void testInterceptorCalling() { // having MyObject target = new MyObject(); MyObject proxy = GrapheneProxy.getProxyForTarget(null, target); // when ((GrapheneProxyInstance) proxy).registerInterceptor(new Interceptor() { @Override public Object intercept(InvocationContext context) throws Throwable { return context.invoke(); } @Override public int getPrecedence() { return 1; } }); proxy.someMethod(); }
@Override public Object intercept(InvocationContext context) throws Throwable { WebDriver browser = context.getGrapheneContext().getWebDriver(); if (indexOfFrame != -1) { browser.switchTo().frame(indexOfFrame); } else if (nameOrIdOfFrame != null) { browser.switchTo().frame(nameOrIdOfFrame); } Object result = null; try { result = context.invoke(); } finally { browser.switchTo().defaultContent(); } if (result instanceof GrapheneProxyInstance) { ((GrapheneProxyInstance) result).registerInterceptor(this); } return result; }
public void register_interceptor(@Observes EventContext<Test> ctx) { invoked = false; try { Test event = ctx.getEvent(); if (event.getTestClass().getJavaClass() == TestInterceptorRegistration.class) { WebDriver browser = org.jboss.arquillian.graphene.context.GrapheneContext.getContextFor(Default.class).getWebDriver(); ((GrapheneProxyInstance) browser).registerInterceptor(new Interceptor() { @Override public Object intercept(InvocationContext context) throws Throwable { invoked = true; return context.invoke(); } @Override public int getPrecedence() { return 0; } }); } } finally { ctx.proceed(); } } }