Package com.gargoylesoftware.htmlunit

Examples of com.gargoylesoftware.htmlunit.WebWindow


    suspendWindowListener();
    // first get the top windows and then close them to avoid ConcurrentModificationException
    final List topWindows = new ArrayList();
    for (final Iterator iter=fWebClient.getWebWindows().iterator(); iter.hasNext();)
    {
      final WebWindow window = (WebWindow) iter.next();
      if (window instanceof TopLevelWindow)
      {
        topWindows.add(window);
      }
    }
    for (final Iterator iter=topWindows.iterator(); iter.hasNext();)
    {
      final TopLevelWindow window = (TopLevelWindow) iter.next();
      window.close();
    }
   
    fWebClient = null;
    fPreviousResponse = null;
    fCurrentResponse = null;
View Full Code Here


      LOG.debug("Window closed (contains: " + event.getWebWindow().getEnclosedPage().getWebResponse().getRequestUrl()
          + ")");
    }

    public void webWindowContentChanged(final WebWindowEvent event) {
      final WebWindow window = event.getWebWindow();
      final WebResponse webResp = event.getNewPage().getWebResponse();
            LOG.info("Content of window changed to " + webResp.getRequestUrl() + " (" + webResp.getContentType() + ")");

      final boolean takeItAsNew;
      if (window instanceof TopLevelWindow && event.getOldPage() == null) {
        takeItAsNew = true;
        LOG.info("Content loaded in newly opened window, its content will become current response");
      } else if (fCurrentResponse.getPage() != null
          && fCurrentResponse.getPage().getEnclosingWindow() == window) {
        takeItAsNew = true;
        LOG.info("Content of current window changed, it will become current response");
      }
      // content loaded in an other window as the "current" one
      // by js becomes "current" only if new top window is opened
      else if (getWebClient().getJavaScriptEngine() == null
          || !getWebClient().getJavaScriptEngine().isScriptRunning()) {
        if (window instanceof FrameWindow
            && !HtmlPage.READY_STATE_COMPLETE.equals(
            ((FrameWindow) window).getEnclosingPage().getDocumentElement().getReadyState())) {
          LOG.info("Content of frame window has changed without javascript while enclosing page is loading, "
              + "it will NOT become current response");
          LOG.debug("Enclosing page's state: " + ((FrameWindow) window).getEnclosingPage().getDocumentElement().getReadyState());
          LOG.debug("Enclosing page's url: " + ((FrameWindow) window).getEnclosingPage().getWebResponse().getRequestUrl());
          takeItAsNew = false;
        } else {
          LOG.info("Content of window changed without javascript, it will become current response");
          takeItAsNew = true;
        }
      } else {
        LOG.info("Content of window changed with javascript, it will NOT become current response");
        takeItAsNew = false;
      }

      if (takeItAsNew) {
        saveResponseAsCurrent(window.getEnclosedPage());
      }
    }
View Full Code Here

      page = (HtmlPage) context.getCurrentResponse();
    } else { // start from the page in the top window
      page = (HtmlPage) context.getCurrentResponse().getEnclosingWindow().getTopWindow().getEnclosedPage();
    }

    final WebWindow frameWindow = getFrame(page, fName, fHtmlId);

    if (frameWindow == null) {
      throw new StepFailedException(getStepLabel() + " Frame not found with name: " + fName + " available: "
         + page.getFrames(),
         this);
    }
    return frameWindow.getEnclosedPage();
  }
View Full Code Here

    {
      LOG.debug("Asked for frame with special name \"_top\", returning the top window for the current page");
      return htmlPage.getEnclosingWindow().getTopWindow();
    }
   
    final WebWindow theFrame;
   
    // first look at the frames directly contained in the page
    if (htmlId != null)
    {
      theFrame = getFrameById(htmlPage, htmlId);
    }
    else // by name
    {
      theFrame = getFrameByName(htmlPage, name);
    }
   
    if (theFrame != null)
    {
      return theFrame;
    }

    // if not a top level frame, perhaps is it a nested frame
    for (final Iterator iter = htmlPage.getFrames().iterator(); iter.hasNext();) {
      final WebWindow elt = (WebWindow) iter.next();
      if (elt.getEnclosedPage() instanceof HtmlPage) {
        LOG.debug("looking at subframes of \"" + elt.getName() + "\": " + elt);
        final WebWindow frame = getFrame((HtmlPage) elt.getEnclosedPage(), name, htmlId);
        if (frame != null) {
          return frame;
        }
      }
    }
View Full Code Here

    public void doExecute() throws Exception {
        LOG.debug("Selecting window " + getName());
        final Context context = getContext();
        final WebClient webClient = context.getWebClient();
        final WebWindow window = findTopLevelWindow(webClient);
        if (window == null) {
          final StepFailedException sfe = new StepFailedException("No window found");
          sfe.addDetail("available windows", getAvailableWindowsMessage(webClient));
          throw sfe;
        }

        context.saveResponseAsCurrent(window.getEnclosedPage());
    }
View Full Code Here

     *
     * @param webClient
     * @return <code>null</code> if not found
     */
    WebWindow findTopLevelWindow(final WebClient webClient) {
      final WebWindow result;
    if (getName() != null) {
      result = findTopLevelWindowByName(webClient);
    }
    else if (getTitle() != null) {
      result = findTopLevelWindowByTitle(webClient);
View Full Code Here

       return result;
    }
   
    WebWindow findTopLevelWindowByName(final WebClient webClient) {
        for (final Iterator iter = webClient.getWebWindows().iterator(); iter.hasNext();) {
            final WebWindow window = (WebWindow) iter.next();
            if (window instanceof TopLevelWindow && window.getName().equals(getName())) {
                return window;
            }
        }
        return null;
    }
View Full Code Here

        return null;
    }

    WebWindow findTopLevelWindowByTitle(final WebClient webClient) {
        for (final Iterator iter = webClient.getWebWindows().iterator(); iter.hasNext();) {
            final WebWindow window = (WebWindow) iter.next();
            if (window instanceof TopLevelWindow)
             {
              final Page containedPage = window.getEnclosedPage();
              if (containedPage instanceof HtmlPage
                  && getTitle().equals(((HtmlPage) containedPage).getTitleText())) {
                return window;
              }
            }
View Full Code Here

   
    WebWindow findTopLevelWindowByIndex(final WebClient webClient) {
      int count = 0;
      int index = ConversionUtil.convertToInt(getIndex(), 0);
        for (final Iterator iter = webClient.getWebWindows().iterator(); iter.hasNext();) {
            final WebWindow window = (WebWindow) iter.next();
            if (window instanceof TopLevelWindow && (count++ == index)) {
                return window;
            }
        }
       
View Full Code Here

   
    static String getAvailableWindowsMessage(final WebClient webClient) {
      final StringBuffer sb = new StringBuffer();
        int i = 0;
        for (Iterator iter = webClient.getWebWindows().iterator(); iter.hasNext();) {
            final WebWindow curWindow = (WebWindow) iter.next();
            if (curWindow instanceof TopLevelWindow) {
              final Page page = curWindow.getEnclosedPage();
              if (i > 0)
                sb.append("\n");
              sb.append("index: " + i + ", name: >" + curWindow.getName() + "<");
              if (page instanceof HtmlPage) {
                sb.append(", title: >" + ((HtmlPage) page).getTitleText() + "<");
              }
              else {
                sb.append(", " + page.getWebResponse().getContentType());
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.WebWindow

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.