Package com.gargoylesoftware.htmlunit

Examples of com.gargoylesoftware.htmlunit.WebWindow


  @SecondsLong(4)
  @TestType(Type.ACCEPTANCE)
  public void testPushing() throws Exception {
    WebClient c = new WebClient();
    WebWindow w = new TopLevelWindow("1", c);
    c.setCurrentWindow(w);
    HtmlPage p = c.getPage(TEST_URL);
    Thread.sleep(4000);
    int current = Integer.parseInt(p.getElementById("content").getFirstChild().getFirstChild().getTextContent().trim());
    if (current < 3 || current > 5) {
View Full Code Here


  @SecondsLong(12)
  @TestType(Type.ACCEPTANCE)
  public void testConnectionSharing() throws Exception {
    WebClient c = new WebClient();
    WebWindow w1 = new TopLevelWindow("1", c);
    WebWindow w2 = new TopLevelWindow("2", c);
    c.setCurrentWindow(w1);
    String requestId1 = ((HtmlPage) c.getPage(TEST_URL)).getElementById("requestId").getAttribute("value");
    Thread.sleep(1000);
    c.setCurrentWindow(w2);
    String requestId2 = ((HtmlPage) c.getPage(TEST_URL)).getElementById("requestId").getAttribute("value");
    Thread.sleep(500);
    enableDebug(w1);
    enableDebug(w2);
    Thread.sleep(10000);
    System.out.println(getLogForWindows(w1,w2));
    int current = Integer.parseInt(((HtmlPage) w1.getEnclosedPage()).getElementById("content").getFirstChild().getFirstChild().getTextContent().trim());
    if (current < 9 || current > 12) {
      throw new Exception("The value is not in the expected interval:[9,12] for Window 1. The current value:" + current);
    }
    current = Integer.parseInt(((HtmlPage) w2.getEnclosedPage()).getElementById("content").getFirstChild().getFirstChild().getTextContent().trim());
    if (current < 9 || current > 12) {
      throw new Exception("The value is not in the expected interval:[9,12] for Window 2. The current value:" + current);
    }
    if (getLogForWindows(w2).contains("pushnotifications") || getLogForWindows(w1).contains("pushnotifications") == false) {
      throw new Exception("Window 2 is making permanent requests or Window 1 don't");
View Full Code Here

  @Only
  @SecondsLong(25)
  @TestType(Type.ACCEPTANCE)
  public void testFailover() throws Exception {
    WebClient c = new WebClient();
    WebWindow w1 = new TopLevelWindow("1", c);
    WebWindow w2 = new TopLevelWindow("2", c);
    c.setCurrentWindow(w1);
    c.getPage(TEST_URL);
    Thread.sleep(500);
    enableDebug(w1);
    Thread.sleep(500);
    c.setCurrentWindow(w2);
    c.getPage(TEST_URL);
    Thread.sleep(500);
    enableDebug(w2);
    Thread.sleep(4000);
    c.deregisterWebWindow(w1);
    Thread.sleep(20000);
    System.out.println(getLogForWindows(w1,w2));
    int current = Integer.parseInt(((HtmlPage) w2.getEnclosedPage()).getElementById("content").getFirstChild().getFirstChild().getTextContent().trim());
    if (current < 23 || current > 25) {
      throw new Exception("The value is not in the expected interval:[23,25] for Window 2. The current value:" + current);
    }
    c.getPage(TEST_URL_PREFIX + "/leaving/?requestId=" + ((HtmlPage) w2.getEnclosedPage()).getElementById("requestId").getAttribute("value"));
  }
View Full Code Here

     // 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();
     }

   }
View Full Code Here

        // getUrl() is not visible
        String currentUrl = window.jsxGet_location().toString();
        currentUrl = getUrlBeforeHash(currentUrl);
        String newUrl = getUrlBeforeHash((String) args[0].getValue());
        if (!newUrl.equals(currentUrl)) {
          WebWindow webWindow = window.getWebWindow();
          do {
            webWindow.getJobManager().removeAllJobs();
            webWindow = webWindow.getParentWindow();
          } while (webWindow != webWindow.getTopWindow());
        }
      }
      result = jsEngine.callFunction(htmlPage, jsFunction, jsContext, window,
          jsThis, jsArgs);    
    } catch (JavaScriptException ex) {
View Full Code Here

        // getUrl() is not visible
        String currentUrl = window.jsxGet_location().toString();
        currentUrl = getUrlBeforeHash(currentUrl);
        String newUrl = getUrlBeforeHash((String) args[0].getValue());
        if (!newUrl.equals(currentUrl)) {
          WebWindow webWindow = window.getWebWindow();
          do {
            webWindow.getJobManager().removeAllJobs();
            webWindow = webWindow.getParentWindow();
          } while (webWindow != webWindow.getTopWindow());
        }
      }
      result = jsEngine.callFunction(htmlPage, jsFunction, jsContext, window,
          jsThis, jsArgs);    
    } catch (JavaScriptException ex) {
View Full Code Here

      public void handleRefresh(final Page page, final URL url, final int iTimeBeforeRefresh) throws IOException {
        final boolean bRefresh = bRefreshAll || (bUseDelay && iTimeBeforeRefresh <= acceptedRefreshDelay);
        if (bRefresh)
        {
          LOG.info("Performing refresh to " + url + " (delay: " + iTimeBeforeRefresh + ") according to configuration");
              final WebWindow window = page.getEnclosingWindow();
              if (window == null) {
                  return;
              }
              final WebClient client = window.getWebClient();
              client.getPage(window, new WebRequestSettings(url));
        }
        else
        {
          LOG.info("no refresh performed to " + url + " (delay: " + iTimeBeforeRefresh + ") according to configuration");
View Full Code Here

            mockConnection.setDefaultResponse(responseBytes, 200, "ok", contentType);
           
            // htmlUnit does't currently follow the "current window"
            // check that our faked content will be loaded in what WebTest considers as the "current window"
            // cf WT-293
            final WebWindow currentTopWindow = context.getCurrentResponse().getEnclosingWindow().getTopWindow();
            // with the <previousResponse/> it may happen that the window is not registerd anymore
            if (webClient.getWebWindows().contains(currentTopWindow))
            {
              webClient.setCurrentWindow(currentTopWindow);
            }
View Full Code Here

    // test if window of current response has not been closed
    if (fCurrentResponse.getPage() != null
        && !fWebClient.getWebWindows().contains(fCurrentResponse.getPage().getEnclosingWindow())) {
      LOG.info("The window containing current response has been closed, "
          + "the content of the last opened window will become the current response");
      final WebWindow window = (WebWindow) fWindows.peek();
      saveResponseAsCurrent(window.getEnclosedPage());
    }
    return fCurrentResponse.getPage();
  }
View Full Code Here

    }
    return (HtmlPage) getCurrentResponse();
  }

  public void restorePreviousResponse() {
    final WebWindow window = fPreviousResponse.getPage().getEnclosingWindow();
    if (!fWebClient.getWebWindows().contains(window)) {
      // register the window "back" to the browser
      fWebClient.registerWebWindow(window);
    }
    saveResponseAsCurrent(fPreviousResponse);
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.