private void cleanUp() { Page p = page.get(); if (p != null) { p.cleanUp(); } for (WebWindow window : webClient.get().getWebWindows()) { window.getJobManager().removeAllJobs(); } page.remove(); webClient.get().close(); webClient.remove(); }
@Override public int getWindowCount() { return wc.getWebWindows().size(); }
public HtmlUnitDriverIterator() { List<WebWindow> allWindows = new ArrayList<WebWindow>(); for (WebWindow window : webClient.getWebWindows()) { WebWindow top = window.getTopWindow(); if (!allWindows.contains(top)) allWindows.add(top); } underlyingIterator = allWindows.iterator(); }
@Override public void gotoWindow(int windowID) { setMainWindow(wc.getWebWindows().get(windowID)); }
public void valueUnbound(HttpSessionBindingEvent httpSessionBindingEvent) { // This is the recommended cleanup code ("close the browser windows") // as per HtmlUnit issue: // https://sourceforge.net/tracker/?func=detail&atid=448266&aid=2014629&group_id=47038 // ----------------------------------------------------------------------------------- // first get the top windows and then close them to avoid ConcurrentModificationException final List<TopLevelWindow> topWindows = new ArrayList<TopLevelWindow>(); for (final Iterator<WebWindow> iter=webClient.getWebWindows().iterator();iter.hasNext();) { final WebWindow window = iter.next(); if (window instanceof TopLevelWindow) { topWindows.add((TopLevelWindow)window); } } for (final Iterator<TopLevelWindow> iter=topWindows.iterator(); iter.hasNext();) { final TopLevelWindow window = iter.next(); window.close(); } }
private void cleanUp() { page.get().cleanUp(); for (WebWindow window : webClient.get().getWebWindows()) { window.getJobManager().removeAllJobs(); } page.remove(); webClient.get().close(); webClient.remove(); }
/** * Indicates if this window is closed. * @return <code>true</code> if this window is closed */ public boolean jsxGet_closed() { return !getWebWindow().getWebClient().getWebWindows().contains(getWebWindow()); }
protected void closeWebClient(WebClient wc) { List<WebWindow> windows = wc.getWebWindows(); for (WebWindow wd : windows) { // wd.getThreadManager().interruptAll(); wd.getJobManager().removeAllJobs(); } wc.closeAllWindows(); }
/** * Returns a list containing all the frames (from frame and iframe tags) in this page. * @return a list of {@link FrameWindow} */ public List<FrameWindow> getFrames() { final List<FrameWindow> list = new ArrayList<FrameWindow>(); final WebWindow enclosingWindow = getEnclosingWindow(); for (final WebWindow window : getWebClient().getWebWindows()) { // quite strange but for a TopLevelWindow parent == self if (enclosingWindow == window.getParentWindow() && enclosingWindow != window) { list.add((FrameWindow) window); } } return list; }
/** * Indicates if this window is closed. * @return <code>true</code> if this window is closed */ public boolean jsxGet_closed() { return !getWebWindow().getWebClient().getWebWindows().contains(getWebWindow()); }
/** * Indicates if this window is closed. * @return <code>true</code> if this window is closed */ public boolean jsxGet_closed() { return !getWebWindow().getWebClient().getWebWindows().contains(getWebWindow()); }
/** * Returns a list containing all the frames (from frame and iframe tags) in this page. * @return a list of {@link FrameWindow} */ public List<FrameWindow> getFrames() { final List<FrameWindow> list = new ArrayList<FrameWindow>(); final WebWindow enclosingWindow = getEnclosingWindow(); for (final WebWindow window : getWebClient().getWebWindows()) { // quite strange but for a TopLevelWindow parent == self if (enclosingWindow == window.getParentWindow() && enclosingWindow != window) { list.add((FrameWindow) window); } } return list; }
/** * Return the first open window with the given title. */ private WebWindow getWindowByTitle(String title) { for (WebWindow window : wc.getWebWindows()) { if (window.getEnclosedPage() instanceof HtmlPage && ((HtmlPage) window.getEnclosedPage()).getTitleText() .equals(title)) { return window; } } return null; }
/** * Returns a list containing all the frames (from frame and iframe tags) in this page. * @return a list of {@link FrameWindow} */ public List<FrameWindow> getFrames() { final List<FrameWindow> list = new ArrayList<FrameWindow>(); final WebWindow enclosingWindow = getEnclosingWindow(); for (final WebWindow window : getWebClient().getWebWindows()) { // quite strange but for a TopLevelWindow parent == self if (enclosingWindow == window.getParentWindow() && enclosingWindow != window) { list.add((FrameWindow) window); } } return list; }
public Set<String> getWindowHandles() { Set<String> allHandles = new HashSet<String>(); List<WebWindow> allWindows = webClient.getWebWindows(); for (WebWindow window : allWindows) { WebWindow top = window.getTopWindow(); if (top.getName() == null || "".equals(top.getName())) { nameWindow(top); } allHandles.add(top.getName()); } return allHandles; }
@Override public String getSource(final DebuggableScript script) { String sourceName = script.getSourceName(); if (sourceName.endsWith("(eval)") || sourceName.endsWith("(Function)")) { return null; // script is result of eval call. Rhino already knows the source and we don't } if (sourceName.startsWith("script in ")) { sourceName = StringUtils.substringBetween(sourceName, "script in ", " from"); for (final WebWindow ww : client.getWebWindows()) { final WebResponse wr = ww.getEnclosedPage().getWebResponse(); if (sourceName.equals(wr.getWebRequest().getUrl().toString())) { return wr.getContentAsString(); } } } return null; } };
/** Initializes the web client to wait for, registering opened windows and * listening for new windows. * @param theClient Web client to wait. Cannot be null. */ private void initialize(final WebClient theClient) { theClient.addWebWindowListener(webWindowListener); theClient.getOptions().setThrowExceptionOnScriptError(false); theClient.setJavaScriptErrorListener(javaScriptErrorListener); for (WebWindow webWindow : theClient.getWebWindows()) { if (!windows.contains(webWindow) && webWindow.getScriptObject() != null) { windows.add(webWindow); } } }
@Override public String getSource(final DebuggableScript script) { String sourceName = script.getSourceName(); if (sourceName.endsWith("(eval)") || sourceName.endsWith("(Function)")) { return null; // script is result of eval call. Rhino already knows the source and we don't } if (sourceName.startsWith("script in ")) { sourceName = StringUtils.substringBetween(sourceName, "script in ", " from"); for (final WebWindow ww : client.getWebWindows()) { final WebResponse wr = ww.getEnclosedPage().getWebResponse(); if (sourceName.equals(wr.getWebRequest().getUrl().toString())) { return wr.getContentAsString(); } } } return null; } };
@Override public WebDriver window(String windowId) { try { WebWindow window = getWebClient().getWebWindowByName(windowId); return finishSelecting(window); } catch (WebWindowNotFoundException e) { List<WebWindow> allWindows = getWebClient().getWebWindows(); for (WebWindow current : allWindows) { WebWindow top = current.getTopWindow(); if (String.valueOf(System.identityHashCode(top)).equals(windowId)) { return finishSelecting(top); } } throw new NoSuchWindowException("Cannot find window: " + windowId); } }
@Override public void close() { getWebClient(); // check that session is active WebWindow thisWindow = getCurrentWindow(); // check that the current window is active if (getWebClient().getWebWindows().size() == 1) { // closing the last window is equivalent to quit quit(); } else { if (thisWindow != null) { alert.close(); ((TopLevelWindow) thisWindow.getTopWindow()).close(); } if (getWebClient().getWebWindows().size() == 0) { quit(); } } }