/** * Performs the given action in a context associated to this browser actions. * * @param <T> return type of the given action * @param action action to be invoked in the context * @return value returned by the given action * @throws Exception */ public <T> T performAction(Callable<T> action) throws Exception { if (currentBrowserActions.get() != null && currentBrowserActions.get() != this) { throw new IllegalStateException("There is an browser interleaving of " + currentBrowserActions().getName() + " and " + this.getName() + "."); } currentBrowserActions.set(this); lastBrowserActions.set(this); try { return action.call(); } finally { currentBrowserActions.set(null); } }
if (context == null) { try { context = new LazyContext(qualifier, new BrowserActions(qualifier.getName())); context.handler = GrapheneContextualHandler.forFuture(context, context.getFutureTarget()); GrapheneProxyInstance proxy = (GrapheneProxyInstance) context.getWebDriver(); 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 {
/** * Sets the current browser context's copy of this browser-local variable * to the specified value. Most subclasses will have no need to * override this method, relying solely on the {@link #initialValue} * method to set the values of browser-locals. * * @param value the value to be stored in the current browser context's copy of * this browser-local. * @throws IllegalStateException if there is no active browser context */ public void set(T value) { BrowserActions.currentBrowserActions().browserLocals.put(this, value); }
/** * 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); } }
/** * Returns the value in the last browser context's copy of this * browser-local variable. If the variable has no value for the * last browser context, it is first initialized to the value returned * by an invocation of the {@link #initialValue} method. * * <p>If the last browser context is not available, null is returned. * * @return the last browser context's value of this browser-local */ public T getLast() { BrowserActions browser = BrowserActions.lastBrowserActions(); if (browser == null) { return null; } T result = (T) browser.browserLocals.get(this); if (result == null) { T init = initialValue(); if (init != null) { browser.browserLocals.put(this, init); return init; } } return result; }
if (context == null) { try { context = new LazyContext(qualifier, new BrowserActions(qualifier.getName())); context.handler = GrapheneContextualHandler.forFuture(context, context.getFutureTarget()); GrapheneProxyInstance proxy = (GrapheneProxyInstance) context.getWebDriver(); 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 current browser context's value for this browser-local * variable. If this browser-local variable is subsequently * {@linkplain #get read} by the current browser context, its value will be * reinitialized by invoking its {@link #initialValue} method, * unless its value is {@linkplain #set set} by the current browser context * in the interim. This may result in multiple invocations of the * <tt>initialValue</tt> method in the current browser context. * * @throws IllegalStateException if there is no active browser context */ public void remove() { BrowserActions.currentBrowserActions().browserLocals.remove(this); }
/** * 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); } }
/** * Returns the value in the last browser context's copy of this * browser-local variable. If the variable has no value for the * last browser context, it is first initialized to the value returned * by an invocation of the {@link #initialValue} method. * * <p>If the last browser context is not available, null is returned. * * @return the last browser context's value of this browser-local */ public T getLast() { BrowserActions browser = BrowserActions.lastBrowserActions(); if (browser == null) { return null; } T result = (T) browser.browserLocals.get(this); if (result == null) { T init = initialValue(); if (init != null) { browser.browserLocals.put(this, init); return init; } } return result; }
/** * Performs the given action in a context associated to this browser actions. * * @param <T> return type of the given action * @param action action to be invoked in the context * @return value returned by the given action * @throws Exception */ public <T> T performAction(Callable<T> action) throws Exception { if (currentBrowserActions.get() != null && currentBrowserActions.get() != this) { throw new IllegalStateException("There is an browser interleaving of " + currentBrowserActions().getName() + " and " + this.getName() + "."); } currentBrowserActions.set(this); lastBrowserActions.set(this); try { return action.call(); } finally { currentBrowserActions.set(null); } }
/** * Sets the current browser context's copy of this browser-local variable * to the specified value. Most subclasses will have no need to * override this method, relying solely on the {@link #initialValue} * method to set the values of browser-locals. * * @param value the value to be stored in the current browser context's copy of * this browser-local. * @throws IllegalStateException if there is no active browser context */ public void set(T value) { BrowserActions.currentBrowserActions().browserLocals.put(this, value); }
return ((GrapheneContextImpl) context).getBrowserActions().performAction(new Callable<Object>() { @Override public Object call() throws Exception {
/** * Removes the current browser context's value for this browser-local * variable. If this browser-local variable is subsequently * {@linkplain #get read} by the current browser context, its value will be * reinitialized by invoking its {@link #initialValue} method, * unless its value is {@linkplain #set set} by the current browser context * in the interim. This may result in multiple invocations of the * <tt>initialValue</tt> method in the current browser context. * * @throws IllegalStateException if there is no active browser context */ public void remove() { BrowserActions.currentBrowserActions().browserLocals.remove(this); }
return ((GrapheneContextImpl) context).getBrowserActions().performAction(new Callable<Object>() { @Override public Object call() throws Exception {
/** * Returns the value in the current browser context's copy of this * browser-local variable. If the variable has no value for the * current browser context, it is first initialized to the value returned * by an invocation of the {@link #initialValue} method. * * @return the current browser context's value of this browser-local * @throws IllegalStateException if there is no active browser context */ public T get() { BrowserActions browser = BrowserActions.currentBrowserActions(); T result = (T) browser.browserLocals.get(this); if (result == null) { T init = initialValue(); if (init != null) { browser.browserLocals.put(this, init); return init; } } return result; }
/** * Returns the value in the current browser context's copy of this * browser-local variable. If the variable has no value for the * current browser context, it is first initialized to the value returned * by an invocation of the {@link #initialValue} method. * * @return the current browser context's value of this browser-local * @throws IllegalStateException if there is no active browser context */ public T get() { BrowserActions browser = BrowserActions.currentBrowserActions(); T result = (T) browser.browserLocals.get(this); if (result == null) { T init = initialValue(); if (init != null) { browser.browserLocals.put(this, init); return init; } } return result; }