Exemplo n.º 1
0
 @JavascriptEnabled
 @Test
 public void testDragAndDropToElement() {
   driver.get(pages.dragAndDropPage);
   WebElement img1 = driver.findElement(By.id("test1"));
   WebElement img2 = driver.findElement(By.id("test2"));
   new Actions(driver).dragAndDrop(img2, img1).perform();
   assertEquals(img1.getLocation(), img2.getLocation());
 }
Exemplo n.º 2
0
 @JavascriptEnabled
 @Test
 public void testElementInDiv() {
   if (Platform.getCurrent().is(Platform.MAC)) {
     System.out.println("Skipping testElementInDiv on Mac: See issue 2281.");
     return;
   }
   driver.get(pages.dragAndDropPage);
   WebElement img = driver.findElement(By.id("test3"));
   Point expectedLocation = img.getLocation();
   drag(img, expectedLocation, 100, 100);
   assertEquals(expectedLocation, img.getLocation());
 }
Exemplo n.º 3
0
  public File takeScreenshot(WebElement element) {
    if (!WebDriverRunner.hasWebDriverStarted()) {
      log.warning("Cannot take screenshot because browser is not started");
      return null;
    }

    WebDriver webdriver = getWebDriver();
    if (!(webdriver instanceof TakesScreenshot)) {
      log.warning("Cannot take screenshot because browser does not support screenshots");
      return null;
    }

    File screen = ((TakesScreenshot) webdriver).getScreenshotAs(OutputType.FILE);

    Point p = element.getLocation();
    Dimension elementSize = element.getSize();

    try {
      BufferedImage img = ImageIO.read(screen);
      BufferedImage dest =
          img.getSubimage(p.getX(), p.getY(), elementSize.getWidth(), elementSize.getHeight());
      ImageIO.write(dest, "png", screen);
      File screenshotOfElement = new File(generateScreenshotFileName());
      FileUtils.copyFile(screen, screenshotOfElement);
      return screenshotOfElement;
    } catch (IOException e) {
      printOnce("takeScreenshotImage", e);
      return null;
    }
  }
Exemplo n.º 4
0
 /**
  * Find out if an element is stale or not.
  *
  * @param element - An xpath locator
  * @return boolean - True if element location is found, otherwise false.
  * @throws Exception
  */
 public boolean isElementStale(WebElement element) {
   try {
     element.getLocation();
   } catch (StaleElementReferenceException Ex) {
     return true;
   }
   return false;
 }
Exemplo n.º 5
0
  @JavascriptEnabled
  @NoDriverAfterTest
  // We can't reliably resize the window back afterwards, cross-browser, so have to kill the
  // window, otherwise we are stuck with a small window for the rest of the tests.
  // TODO(dawagner): Remove @NoDriverAfterTest when we can reliably do window resizing
  @Test
  public void testShouldAllowUsersToDragAndDropToElementsOffTheCurrentViewPort() {
    driver.get(pages.dragAndDropPage);

    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("window.resizeTo(300, 300);");

    driver.get(pages.dragAndDropPage);
    WebElement img = driver.findElement(By.id("test3"));
    Point expectedLocation = img.getLocation();
    drag(img, expectedLocation, 100, 100);
    assertEquals(expectedLocation, img.getLocation());
  }
  @JavascriptEnabled
  @Test
  public void testShouldBeAbleToDetermineTheLocationOfAnElement() {
    driver.get(pages.xhtmlTestPage);

    WebElement element = driver.findElement(By.id("username"));
    Point location = element.getLocation();

    assertThat(location.getX() > 0, is(true));
    assertThat(location.getY() > 0, is(true));
  }
Exemplo n.º 7
0
  @Test
  public void scrollElementIntoView() {
    WebDriver d = getDriver();

    d.get("https://developer.mozilla.org/en/CSS/Attribute_selectors");
    WebElement aboutGoogleLink = d.findElement(By.partialLinkText("About MDN"));
    Point locationBeforeScroll = aboutGoogleLink.getLocation();
    Point locationAfterScroll =
        ((Locatable) aboutGoogleLink).getLocationOnScreenOnceScrolledIntoView();

    assertTrue(locationBeforeScroll.x >= locationAfterScroll.x);
    assertTrue(locationBeforeScroll.y >= locationAfterScroll.y);
  }
Exemplo n.º 8
0
 @JavascriptEnabled
 @Test
 public void testDragAndDrop() throws Exception {
   if (Platform.getCurrent().is(Platform.MAC)) {
     System.out.println("Skipping testDragAndDrop on Mac: See issue 2281.");
     return;
   }
   driver.get(pages.dragAndDropPage);
   WebElement img = driver.findElement(By.id("test1"));
   Point expectedLocation = img.getLocation();
   drag(img, expectedLocation, 150, 200);
   waitFor(elementLocationToBe(img, expectedLocation));
   drag(img, expectedLocation, -50, -25);
   waitFor(elementLocationToBe(img, expectedLocation));
   drag(img, expectedLocation, 0, 0);
   waitFor(elementLocationToBe(img, expectedLocation));
   drag(img, expectedLocation, 1, -1);
   waitFor(elementLocationToBe(img, expectedLocation));
 }
Exemplo n.º 9
0
  // TODO: This test's value seems dubious at best. The CSS spec does not define how browsers
  // should handle sub-pixel rendering, and every browser seems to be different anyhow:
  // http://ejohn.org/blog/sub-pixel-problems-in-css/
  @JavascriptEnabled
  @Ignore({IE, CHROME, SELENESE, IPHONE, OPERA, ANDROID, SAFARI, OPERA_MOBILE, PHANTOMJS})
  // Reason for Chrome: WebKit bug 28804
  @Test
  public void testShouldHandleNonIntegerPositionAndSize() {
    driver.get(pages.rectanglesPage);

    WebElement r2 = driver.findElement(By.id("r2"));
    String left = r2.getCssValue("left");
    assertTrue("left (\"" + left + "\") should start with \"10.9\".", left.startsWith("10.9"));
    String top = r2.getCssValue("top");
    assertTrue("top (\"" + top + "\") should start with \"10.1\".", top.startsWith("10.1"));
    assertEquals(new Point(11, 10), r2.getLocation());
    String width = r2.getCssValue("width");
    assertTrue("width (\"" + left + "\") should start with \"48.6\".", width.startsWith("48.6"));
    String height = r2.getCssValue("height");
    assertTrue("height (\"" + left + "\") should start with \"49.3\".", height.startsWith("49.3"));
    assertEquals(r2.getSize(), new Dimension(49, 49));
  }
Exemplo n.º 10
0
  @Test
  public void checkLocationAndSizeOfBingSearchBox() {
    WebDriver d = getDriver();
    d.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);

    d.get("http://www.bing.com");
    WebElement searchBox = d.findElement(By.cssSelector("input[name*='q']"));

    assertTrue(
        searchBox.getCssValue("color").contains("rgb(0, 0, 0)")
            || searchBox.getCssValue("color").contains("rgba(0, 0, 0, 1)"));
    assertEquals("", searchBox.getAttribute("value"));
    assertEquals("input", searchBox.getTagName());
    assertEquals(true, searchBox.isEnabled());
    assertEquals(true, searchBox.isDisplayed());
    assertTrue(searchBox.getLocation().getX() >= 200);
    assertTrue(searchBox.getLocation().getY() >= 100);
    assertTrue(searchBox.getSize().getWidth() >= 350);
    assertTrue(searchBox.getSize().getHeight() >= 20);
  }
Exemplo n.º 11
0
 @Override
 public Point getLocation(WebElement element) {
   return element.getLocation();
 }
 @Override
 public Point getLocation() {
   return webElement.getLocation();
 }