@Override public Object intercept(InvocationContext context) throws Throwable { return elementProxy.unwrap(); }
@Override public Object intercept(InvocationContext context) throws Throwable { return elementProxy.unwrap(); }
public static WebElement unwrap(WebElement element) { Preconditions.checkNotNull(element, "The element cannot be null."); WebElement result = element; while (GrapheneProxy.isProxyInstance(result)) { result = ((GrapheneProxyInstance) result).unwrap(); } return result; }
/** * 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; }
/** * 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; }
try { if (target instanceof GrapheneProxyInstance) { target = ((GrapheneProxyInstance) target).unwrap();
try { if (target instanceof GrapheneProxyInstance) { target = ((GrapheneProxyInstance) target).unwrap();
private static boolean isAndroidDriver(Object instance) { if (instance instanceof GrapheneProxyInstance) { return isAndroidDriver(((GrapheneProxyInstance) instance).unwrap()); } // AndroidDriver is RemoteWebDriver if (instance instanceof RemoteWebDriver) { Capabilities capabilities = ((RemoteWebDriver) instance).getCapabilities(); return "android".equals(capabilities.getBrowserName()); } return false; }
private static boolean isAndroidDriver(Object instance) { if (instance instanceof GrapheneProxyInstance) { return isAndroidDriver(((GrapheneProxyInstance) instance).unwrap()); } // AndroidDriver is RemoteWebDriver if (instance instanceof RemoteWebDriver) { Capabilities capabilities = ((RemoteWebDriver) instance).getCapabilities(); return "android".equals(capabilities.getBrowserName()); } return false; }
private WebDriver getTakingScreenshotsBrowser(File screenshotToTake) { WebDriver result = null; try { GrapheneContext context = GrapheneContext.getContextFor(Default.class); result = ((GrapheneProxyInstance) context.getWebDriver(TakesScreenshot.class)).unwrap(); //FIXME remove this try-catch block and bring new solution } catch (IllegalStateException ex) { log.info("The screenshot " + screenshotToTake.getPath() + " hasn't been taken." + " The reason: " + ex.getMessage()); return null; } if (result instanceof ReusableRemoteWebDriver) { result = new Augmenter().augment(result); } return result; }
protected static List<WebElement> dropProxyAndFindElements(By by, SearchContext searchContext) { List<WebElement> webElements; if (searchContext instanceof GrapheneProxyInstance) { if (by instanceof ByJQuery) { webElements = by.findElements(searchContext); } else { webElements = ((SearchContext) ((GrapheneProxyInstance) searchContext).unwrap()).findElements(by); } } else { webElements = searchContext.findElements(by); } List<WebElement> result = new ArrayList<WebElement>(webElements.size()); for (WebElement webElement : webElements) { result.add(new GrapheneElementImpl(webElement)); } return result; }
protected static List<WebElement> dropProxyAndFindElements(By by, SearchContext searchContext) { List<WebElement> webElements; if (searchContext instanceof GrapheneProxyInstance) { if (by instanceof ByJQuery) { webElements = by.findElements(searchContext); } else { webElements = ((SearchContext) ((GrapheneProxyInstance) searchContext).unwrap()).findElements(by); } } else { webElements = searchContext.findElements(by); } List<WebElement> result = new ArrayList<WebElement>(webElements.size()); for (WebElement webElement : webElements) { result.add(new GrapheneElementImpl(webElement)); } return result; }
private WebDriver getTakingScreenshotsBrowser(File screenshotToTake) { WebDriver result = null; try { GrapheneContext context = GrapheneContext.getContextFor(Default.class); result = ((GrapheneProxyInstance) context.getWebDriver(TakesScreenshot.class)).unwrap(); //FIXME remove this try-catch block and bring new solution } catch (IllegalStateException ex) { log.info("The screenshot " + screenshotToTake.getPath() + " hasn't been taken." + " The reason: " + ex.getMessage()); return null; } if (result instanceof ReusableRemoteWebDriver) { result = new Augmenter().augment(result); } return result; }
protected static WebElement dropProxyAndFindElement(By by, SearchContext searchContext) { WebElement result; if (searchContext instanceof GrapheneProxyInstance) { SearchContext unwrapped = ((GrapheneProxyInstance) searchContext).unwrap(); result = unwrapped.findElement(by); } else { result = searchContext.findElement(by); } return new GrapheneElementImpl(result); }
protected static WebElement dropProxyAndFindElement(By by, SearchContext searchContext) { WebElement result; if (searchContext instanceof GrapheneProxyInstance) { SearchContext unwrapped = ((GrapheneProxyInstance) searchContext).unwrap(); result = unwrapped.findElement(by); } else { result = searchContext.findElement(by); } return new GrapheneElementImpl(result); }
@Test public void testEnrichedEqualsToEnriched() { // not strictly reflexivity, but reflexivity at the underlying element level WebElement altEnriched = browser.findElement(By.id(TEST_ELEMENT_ID)); assertNotSame(enriched, altEnriched); assertNotSame(((GrapheneProxyInstance) enriched).unwrap(), ((GrapheneProxyInstance) altEnriched).unwrap()); assertTrue(enriched.equals(altEnriched)); }