Package com.gargoylesoftware.htmlunit

Examples of com.gargoylesoftware.htmlunit.WebClient$CurrentWindowTracker


  @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


  /** Tests that the failing pages' notifications are removed nicely. */
  @SecondsLong(42)
  @TestType(Type.INTEGRATION)
  public void testCleanerNotificationRemoval() throws Exception {
    WebClient c1 = new WebClient();
    WebClient c2 = new WebClient();
    String requestId1 = ((HtmlPage) c1.getPage(TEST_URL)).getElementById("requestId").getAttribute("value");
    String requestId2 = ((HtmlPage) c2.getPage(TEST_URL)).getElementById("requestId").getAttribute("value");
    System.out.println("Pages got");
    c1.closeAllWindows();
    c2.closeAllWindows();
    System.out.println("Windows closed");
    if (c1.getPage(TEST_URL_PREFIX + "/pushnotifications/?requestId=" + requestId1).getWebResponse().getContentAsString().startsWith("SUCCESS") == false) {
      throw new Exception("There should be a notification!");
    }
    System.out.println("Notifications working");
    for (int i = 0; i < 21; i++) {
      Thread.sleep(2000);
      System.out.println("Sending keepalive:" + i);
      if (c1.getPage(TEST_URL_PREFIX + "/keepalive/?requestId=" + requestId1).getWebResponse().getContentAsString().startsWith("SUCCESS") == false) {
        throw new Exception("Keepalive should be successful!");
      }
    }
    System.out.println("All keepalives sent");
    for (int i = 0; i < 20; i++) {
      System.out.println("Getting notification:" + i);
      if (new String(Base64.decodeStandard(c1.getPage(TEST_URL_PREFIX + "/pushnotifications/?requestId=" + requestId1).getWebResponse().getContentAsString().split("[:]")[1])).compareTo(requestId1) != 0) {
        throw new Exception("Only the first page should have notifications!");
      }
    }
    c1.getPage(TEST_URL_PREFIX + "/leaving/?requestId=" + requestId1);
    c2.getPage(TEST_URL_PREFIX + "/leaving/?requestId=" + requestId2);
  }
View Full Code Here

  }

  @SecondsLong(0)
  @TestType(Type.INTEGRATION)
  public void testLeaving() throws Exception {
    WebClient c = new WebClient();
    String requestId = ((HtmlPage) c.getPage(TEST_URL)).getElementById("requestId").getAttribute("value");
    if (c.getPage(TEST_URL_PREFIX + "/keepalive/?requestId=" + requestId).getWebResponse().getContentAsString().startsWith("SUCCESS") == false) {
      throw new Exception("Initial keepalive should be successfull");
    }
    if (c.getPage(TEST_URL_PREFIX + "/leaving/?requestId=" + requestId).getWebResponse().getContentAsString().startsWith("SUCCESS") == false) {
      throw new Exception("Leaving should always be successfull");
    }
    if (c.getPage(TEST_URL_PREFIX + "/keepalive/?requestId=" + requestId).getWebResponse().getContentAsString().startsWith("FAILURE") == false) {
      throw new Exception("Keepalive should fail after leaving");
    }
  }
View Full Code Here

   }

   protected HtmlAction getWebClient(String path) throws FailingHttpStatusCodeException, IOException
   {
      try {
         WebClient client = new WebClient();
         return new HtmlAction(client, (HtmlPage) client.getPage(getBaseURL() + getContextPath() + path));
      }
      catch (MalformedURLException e) {
         throw new RuntimeException(e);
      }
   }
View Full Code Here

    private final Properties properties = new Properties();

    public void setUp()
        throws IOException
    {
        client = new WebClient();
        properties.load( getClass().getResourceAsStream( "/integration-test.properties" ) );
        baseUrl = properties.getProperty( "baseUrl" );
    }
View Full Code Here

    private final Properties properties = new Properties();

    public void setUp()
        throws IOException
    {
        client = new WebClient();
        properties.load( getClass().getResourceAsStream( "/integration-test.properties" ) );
        baseUrl = properties.getProperty( "baseUrl" );
    }
View Full Code Here

    server.stop();
  }

  @Before
  public void setUp() throws Exception {
    webClient = new WebClient();
    // NicelyResynchronizingAjaxController changes XHR calls from asynchronous
    // to synchronous, saving the test from needing to wait or sleep for XHR
    // completion.
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());
    webClient.waitForBackgroundJavaScript(120000)// Closure can take a long time...
View Full Code Here

    public static final String testUrl = "http://localhost:8080/sample-bigbank-webclient/";

    public void testBigBankDefault() throws Exception {
        System.err.println("Running: testcase:");
        // New HTMLunit web client
        WebClient client = new WebClient();
        client.setRedirectEnabled(true);

        // Going to have the WebClient connect to this URL
        URL url = new URL(testUrl);
        HtmlPage page = (HtmlPage) client.getPage(url);
        // System.out.println(page.getTitleText());

        // Check response code
        WebResponse resp = page.getWebResponse();
        assertTrue(resp.getStatusCode() <= 200);
View Full Code Here

  public void testHelloWorldDefault() throws Exception
  {
    System.err.println("Running: testcase:");
    // New HTMLunit web client
    WebClient client = new WebClient();
    // Going to have the WebClient connect to this URL
    URL url = new URL(testUrl);
    HtmlPage page = (HtmlPage)client.getPage(url);
    //System.out.println(page.getTitleText());
   
    // Check response code
    WebResponse resp = page.getWebResponse();
    assertTrue(resp.getStatusCode() <= 200);
View Full Code Here

    }

    @Test
    public void testStoreWidget() throws FailingHttpStatusCodeException, MalformedURLException, IOException {
        WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3);
        webClient.setRedirectEnabled(true);
        webClient.setThrowExceptionOnScriptError(false);
        //webClient.waitForBackgroundJavaScript(100000);
        //webClient.waitForBackgroundJavaScriptStartingBefore(100000);
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());

        HtmlPage page = (HtmlPage) webClient.getPage("http://localhost:8080/store/store.html");

        HtmlForm form = (HtmlForm) page.getFormByName("catalogForm");

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
       
        HtmlCheckBoxInput catalogItems = (HtmlCheckBoxInput) form.getInputByName("items");

        System.out.println(">>>" + catalogItems.getAttribute("value"));
        Assert.assertEquals("Apple - $2.99", catalogItems.getAttribute("value"));

        webClient.closeAllWindows();
    }
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.WebClient$CurrentWindowTracker

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.