Пример #1
0
  @Test
  public void pageSourceShouldReturnSourceOfFocusedFrame() throws InterruptedException {
    WebDriver d = getDriver();
    d.get("http://docs.wpm.neustar.biz/testscript-api/index.html");

    // Compare source before and after the frame switch
    String pageSource = d.getPageSource();
    d.switchTo().frame("classFrame");
    String framePageSource = d.getPageSource();
    assertFalse(pageSource.equals(framePageSource));

    assertTrue(
        "Page source was: " + framePageSource, framePageSource.contains("Interface Summary"));
  }
Пример #2
0
  protected File savePageSourceToFile(String fileName, WebDriver webdriver, boolean retryIfAlert) {
    File pageSource = new File(reportsFolder, fileName + ".html");

    try {
      writeToFile(webdriver.getPageSource(), pageSource);
    } catch (UnhandledAlertException e) {
      if (retryIfAlert) {
        try {
          Alert alert = webdriver.switchTo().alert();
          log.severe(e + ": " + alert.getText());
          alert.accept();
          savePageSourceToFile(fileName, webdriver, false);
        } catch (Exception unableToCloseAlert) {
          log.severe("Failed to close alert: " + unableToCloseAlert);
        }
      } else {
        printOnce("savePageSourceToFile", e);
      }
    } catch (UnreachableBrowserException e) {
      writeToFile(e.toString(), pageSource);
      return pageSource;
    } catch (Exception e) {
      writeToFile(e.toString(), pageSource);
      printOnce("savePageSourceToFile", e);
    }
    return pageSource;
  }
Пример #3
0
  @Ignore // Ignored because you need to kickstart Python SimpleHTTPServer before it can run
  @Test
  public void shouldSwitchToTheRightFrame_issue226() {
    // NOTE: before starting this test,
    // run `python -m SimpleHTTPServer` from within `test/testcase-issue_226`.
    // This will launch a minimal webserver to serve the pages for this test.
    WebDriver d = getDriver();

    // Load "outside.html" and check it's the right one
    d.get("http://localhost:8000/outside.html");
    assertTrue(d.getPageSource().contains("Editing testDotAtEndDoesNotDelete"));
    assertEquals(2, d.findElements(By.tagName("iframe")).size());

    // Find the iframe with class "gwt-RichTextArea"
    WebElement iframeRichTextArea = d.findElement(By.className("gwt-RichTextArea"));

    // Switch to the iframe via WebElement and check it's the right one
    d.switchTo().frame(iframeRichTextArea);
    assertEquals(0, d.findElements(By.tagName("title")).size());
    assertFalse(d.getPageSource().contains("Editing testDotAtEndDoesNotDelete"));
    assertEquals(0, d.findElements(By.tagName("iframe")).size());

    // Switch back to the main frame and check it's the right one
    d.switchTo().defaultContent();
    assertEquals(2, d.findElements(By.tagName("iframe")).size());

    // Switch again to the iframe, this time via it's "frame number" (i.e. 0 to n)
    d.switchTo().frame(0);
    assertEquals(0, d.findElements(By.tagName("title")).size());
    assertFalse(d.getPageSource().contains("Editing testDotAtEndDoesNotDelete"));
    assertEquals(0, d.findElements(By.tagName("iframe")).size());

    // Switch back to the main frame and check it's the right one
    d.switchTo().defaultContent();
    assertEquals(2, d.findElements(By.tagName("iframe")).size());

    // Switch to the second frame via it's "frame number"
    d.switchTo().frame(1);
    assertEquals(1, d.findElements(By.tagName("title")).size());
    assertEquals(0, d.findElements(By.tagName("iframe")).size());
    assertTrue(d.getPageSource().contains("WYSIWYG Editor Input Template"));

    // Switch again to the main frame
    d.switchTo().defaultContent();
    assertEquals(2, d.findElements(By.tagName("iframe")).size());
  }
Пример #4
0
  @Test(expected = TimeoutException.class)
  public void shouldTimeoutWhileChangingIframeSource() {
    final String iFrameId = "iframeId";

    // Define HTTP response for test
    server.setGetHandler(
        new HttpRequestCallback() {
          @Override
          public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
            String pathInfo = req.getPathInfo();
            ServletOutputStream out = res.getOutputStream();

            if (pathInfo.endsWith("iframe_content.html")) {
              // nested frame 1
              out.println("iframe content");
            } else {
              // main page
              out.println(
                  "<html>\n"
                      + "<body>\n"
                      + "  <iframe id='"
                      + iFrameId
                      + "'></iframe>\n"
                      + "  <script>\n"
                      + "  setTimeout(function() {\n"
                      + "    document.getElementById('"
                      + iFrameId
                      + "').src='iframe_content.html';\n"
                      + "  }, 2000);\n"
                      + "  </script>\n"
                      + "</body>\n"
                      + "</html>");
            }
          }
        });

    // Launch Driver against the above defined server
    WebDriver d = getDriver();
    d.get(server.getBaseUrl());

    // Switch to iframe
    d.switchTo().frame(iFrameId);
    assertEquals(0, d.findElements(By.id(iFrameId)).size());
    assertFalse(d.getPageSource().toLowerCase().contains("iframe content"));

    new WebDriverWait(d, 5)
        .until(
            new Predicate<WebDriver>() {
              @Override
              public boolean apply(@Nullable WebDriver driver) {
                assertEquals(0, driver.findElements(By.id(iFrameId)).size());
                return (Boolean) ((JavascriptExecutor) driver).executeScript("return false;");
              }
            });
  }
Пример #5
0
  @Test
  public void test35() throws Exception {

    driver.get(baseUrl + "/accountType/list");

    driver.findElement(By.xpath("//strong[text()='Direct Customer']")).click();

    driver.findElement(By.cssSelector("a.submit.edit > span")).click();
    driver.findElement(By.id("creditLimitAsDecimal")).clear();
    driver.findElement(By.id("creditLimitAsDecimal")).sendKeys("300.00");
    driver.findElement(By.cssSelector("a.submit.save > span")).click();
    driver.findElement(By.xpath("//strong[text()='Direct Customer']")).click();
    driver.findElement(By.cssSelector("a.submit.edit > span")).click();
    driver.findElement(By.id("creditLimitAsDecimal")).clear();
    driver.findElement(By.id("creditLimitAsDecimal")).sendKeys("200.00");
    driver.findElement(By.cssSelector("a.submit.save > span")).click();
    driver.findElement(By.xpath("//strong[text()='Direct Customer']")).click();

    Assert.assertEquals(driver.getPageSource().contains("US$200.00"), true);
  }
Пример #6
0
 /**
  * Return the source of the page
  *
  * @return
  */
 public String pageSource() {
   return driver.getPageSource();
 }