private WebDriver getWebDriver() { return GrapheneContext.getContextFor(Default.class).getWebDriver(); } }
private GrapheneContext context() { GrapheneContext context = GrapheneContext.lastContext(); if (context == null) { throw new IllegalStateException("The last used Graphene context is not available."); } return context; }
@Override public GrapheneConfiguration getConfiguration() { return getContext(true).getConfiguration(); }
/** * Wraps the {@link WebDriver} instance provided by {@link Drone} in a proxy and sets the driver into context */ @Override public WebDriver enhance(WebDriver driver, Class<? extends Annotation> qualifier) { GrapheneContext grapheneContext = GrapheneContext.setContextFor(configuration.get(), driver, qualifier); Class<?>[] interfaces = GrapheneProxyUtil.getInterfaces(driver.getClass()); return grapheneContext.getWebDriver(interfaces); }
@Override public Object getTarget() { return getContext(true).getWebDriver(); } };
@Override public Object lookup(ArquillianResource resource, Annotation... qualifiers) { return GrapheneContext.getContextFor(ReflectionHelper.getQualifier(qualifiers)); }
final long LIMIT = context.getConfiguration().getJavascriptInstallationLimit(); for (long i=1; i<=5; i++) { try { Object returnValue = executeScriptForCall((JavascriptExecutor) context.getWebDriver(JavascriptExecutor.class), call); Object castedResult = castResult(call, returnValue); return castedResult;
@Before public void before() throws Throwable { Answer invoke = new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return ((InvocationContext) invocation.getArguments()[0]).invoke(); } }; when(interceptor1.intercept(Mockito.any(InvocationContext.class))).thenAnswer(invoke); when(interceptor2.intercept(Mockito.any(InvocationContext.class))).thenAnswer(invoke); context = GrapheneContext.setContextFor(new GrapheneConfiguration(), driver, Default.class); }
@Test public void generated_webelement_implements_WrapsElement_interface() { TestPage page = new TestPage(); getGrapheneEnricher().enrich(page); assertTrue(page.element instanceof WrapsElement); GrapheneContext.setContextFor(new GrapheneConfiguration(), driver, Default.class); when(driver.findElement(Mockito.any(By.class))).thenReturn(element); WebElement wrappedElement = ((WrapsElement) page.element).getWrappedElement(); GrapheneContext.removeContextFor(Default.class); assertThat(wrappedElement, is(instanceOf(GrapheneElement.class))); assertEquals(element, ((GrapheneElement)wrappedElement).getWrappedElement()); }
/** * 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 Class<?> getQualifier() { return context.getQualifier(); }
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."); }
@Override public Object lookup(ArquillianResource resource, Annotation... qualifiers) { return GrapheneContext.getContextFor(ReflectionHelper.getQualifier(qualifiers)); }
/** * Wraps the {@link WebDriver} instance provided by {@link Drone} in a proxy and sets the driver into context */ @Override public WebDriver enhance(WebDriver driver, Class<? extends Annotation> qualifier) { GrapheneContext grapheneContext = GrapheneContext.setContextFor(configuration.get(), driver, qualifier); Class<?>[] interfaces = GrapheneProxyUtil.getInterfaces(driver.getClass()); return grapheneContext.getWebDriver(interfaces); }
final long LIMIT = context.getConfiguration().getJavascriptInstallationLimit(); for (long i=1; i<=5; i++) { try { Object returnValue = executeScriptForCall((JavascriptExecutor) context.getWebDriver(JavascriptExecutor.class), call); Object castedResult = castResult(call, returnValue); return castedResult;
@Before public void prepareTest() { // given MockitoAnnotations.initMocks(this); instance = JSInterfaceFactory.create(GrapheneContext.setContextFor(new GrapheneConfiguration(), executor, Default.class), TestingInterface.class); when(executor.executeScript(Mockito.anyString())).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return answer; } }); when(executor.executeScript("return true;")).thenReturn(true); }
/** * 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; }
@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; } }
private WebDriver getWebDriver() { return GrapheneContext.getContextFor(Default.class).getWebDriver(); } }
@Override public Object getTarget() { return getContext(true).getWebDriver(); } };