private GrapheneContext context() { GrapheneContext context = GrapheneContext.lastContext(); if (context == null) { throw new IllegalStateException("The last used Graphene context is not available."); } return context; }
private GrapheneContext context() { GrapheneContext context = GrapheneContext.lastContext(); if (context == null) { throw new IllegalStateException("The last used Graphene context is not available."); } return context; }
private GrapheneContext getGrapheneContext(SearchContext searchContext) { if (searchContext instanceof GrapheneProxyInstance) { return ((GrapheneProxyInstance) searchContext).getGrapheneContext(); } else { return GrapheneContext.lastContext(); } } }
protected GrapheneContext getGrapheneContext(SearchContext searchContext) { if (searchContext instanceof GrapheneProxyInstance) { return ((GrapheneProxyInstance) searchContext).getContext(); } else { return GrapheneContext.lastContext(); } } }
private GrapheneContext getGrapheneContext(SearchContext searchContext) { if (searchContext instanceof GrapheneProxyInstance) { return ((GrapheneProxyInstance) searchContext).getGrapheneContext(); } else { return GrapheneContext.lastContext(); } } }
/** * When using Firefox and body element is focused, focus on the page from url/address bar, otherwise nothing happens. * Workaround for Selenium issue * <a href="https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/7937">#7937</a> */ public static void performFirefoxKeyboardWorkaround(WebDriver browser) { if (browser instanceof FirefoxDriver) { FirefoxKeyboardWorkaround fkw = JSInterfaceFactory.create(GrapheneContext.lastContext(), FirefoxKeyboardWorkaround.class); // is body element focused and workaround was not invoked? if (!fkw.isInvoked() && fkw.getActiveElementTagName().equalsIgnoreCase("body")) { // insert the button element fkw.insertButtonWorkaround(); // click on the inserted button to focus on the page and remove the button from DOM (after click) fkw.getButtonElement().click(); } } }
private WebElement getProxified() { // right now browser.switchTo().activeElement() is an example of a proxified but not wrapped element // we won't rely on that though, because it could easily change, so instead we'll use the proxifier directly (and in // such a way so as to benefit from the fix relevant to the test) GrapheneContextualHandler handler = GrapheneContextualHandler.forTarget(GrapheneContext.lastContext(), browser); WebElement proxy; try { Method findElement = WebDriver.class.getMethod("findElement", By.class); proxy = (WebElement) handler.invoke(browser, findElement, new Object[] { By.id(TEST_ELEMENT_ID) }); } catch (Throwable e) { throw new RuntimeException(e); } // in case you need to reproduce the problem, create the proxy manually: // Class<?>[] interfaces = GrapheneProxyUtil.getInterfaces(getUnwrapped().getClass()); // WebElement proxy = GrapheneProxy.getProxyForTargetWithInterfaces(GrapheneContext.lastContext(), getUnwrapped(), // interfaces); if (!(proxy instanceof GrapheneProxyInstance) || proxy instanceof GrapheneElement) { // it's not right to use asserts here - not the point of the test // also a caller might use @Test(expected = AssertionError.class) throw new RuntimeException( "Not proxified correctly: " + Arrays.toString(GrapheneProxyUtil.getInterfaces(proxy.getClass()))); } return proxy; }
/** * Creates and inserts a new button to DOM, clicks on it and removes it. * * @param browser */ public static void performUniversalBlur(WebDriver browser) { // reuse FirefoxKeyboardWorkaround FirefoxKeyboardWorkaround fkw = JSInterfaceFactory.create(GrapheneContext.lastContext(), FirefoxKeyboardWorkaround.class); fkw.insertButtonWorkaround(); new Actions(browser).moveToElement(fkw.getButtonElement()).click().perform(); }