/** * Removes the context associated to the given qualifier. * @param qualifier * @see #setContextFor(org.jboss.arquillian.graphene.spi.configuration.GrapheneConfiguration, org.openqa.selenium.WebDriver, java.lang.Class) */ @Override public void removeContextFor(Class<?> qualifier) { final GrapheneContext context = LAZY_CONTEXTS.get().get(qualifier); if (context != null) { try { ((LazyContext) context).getBrowserActions().performAction(new Callable<Void>() { @Override public Void call() throws Exception { CURRENT_CONTEXT.remove(); return null; } }); } catch (Exception ignored) { } LAZY_CONTEXTS.get().remove(qualifier); } ALL_CONTEXTS.get().remove(qualifier); } }
@Override public PageExtensionRegistry getPageExtensionRegistry() { LazyContext context = LAZY_CONTEXTS.get().get(getQualifier()); if (context == null) { return registry; } else { return context.registry; } }
if (context == null) { try { context = new LazyContext(qualifier, new BrowserActions(qualifier.getName())); 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.getBrowserActions().performAction(new Callable<Void>() { @Override public Void call() throws Exception {
if (context == null) { try { context = new LazyContext(qualifier, new BrowserActions(qualifier.getName())); 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.getBrowserActions().performAction(new Callable<Void>() { @Override public Void call() throws Exception {
/** * Removes the context associated to the given qualifier. * @param qualifier * @see #setContextFor(org.jboss.arquillian.graphene.spi.configuration.GrapheneConfiguration, org.openqa.selenium.WebDriver, java.lang.Class) */ @Override public void removeContextFor(Class<?> qualifier) { final GrapheneContext context = LAZY_CONTEXTS.get().get(qualifier); if (context != null) { try { ((LazyContext) context).getBrowserActions().performAction(new Callable<Void>() { @Override public Void call() throws Exception { CURRENT_CONTEXT.remove(); return null; } }); } catch (Exception ignored) { } LAZY_CONTEXTS.get().remove(qualifier); } ALL_CONTEXTS.get().remove(qualifier); } }
@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 Class<?> getQualifier() { if (Default.class.equals(qualifier)) { GrapheneContext context = getContext(false); if (context == null) { return qualifier; } if (context instanceof LazyContext) { return ((LazyContext) context).qualifier; } else { return context.getQualifier(); } } else { return qualifier; } }
@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 Class<?> getQualifier() { if (Default.class.equals(qualifier)) { GrapheneContext context = getContext(false); if (context == null) { return qualifier; } if (context instanceof LazyContext) { return ((LazyContext) context).qualifier; } else { return context.getQualifier(); } } else { return qualifier; } }
@Override public GrapheneConfiguration getConfiguration() { return getContext(true).getConfiguration(); }
@Override public GrapheneConfiguration getConfiguration() { return getContext(true).getConfiguration(); }
@Override public Object getTarget() { return getContext(true).getWebDriver(); } };
@Override public PageExtensionRegistry getPageExtensionRegistry() { LazyContext context = LAZY_CONTEXTS.get().get(getQualifier()); if (context == null) { return registry; } else { return context.registry; } }
@Override public BrowserActions getBrowserActions() { LazyContext context = LAZY_CONTEXTS.get().get(getQualifier()); if (context == null) { return browserActions; } else { return context.browserActions; } }
@Override public PageExtensionInstallatorProvider getPageExtensionInstallatorProvider() { LazyContext context = LAZY_CONTEXTS.get().get(getQualifier()); if (context == null) { return installatorProvider; } else { return context.installatorProvider; } }
@Override public Object getTarget() { return getContext(true).getWebDriver(); } };
@Override public BrowserActions getBrowserActions() { LazyContext context = LAZY_CONTEXTS.get().get(getQualifier()); if (context == null) { return browserActions; } else { return context.browserActions; } }
@Override public PageExtensionInstallatorProvider getPageExtensionInstallatorProvider() { LazyContext context = LAZY_CONTEXTS.get().get(getQualifier()); if (context == null) { return installatorProvider; } else { return context.installatorProvider; } }