示例#1
0
 @JavascriptEnabled
 @Ignore({HTMLUNIT, CHROME, SELENESE})
 public void testDragAndDropToElement() {
   driver.get(dragAndDropPage);
   RenderedWebElement img1 = (RenderedWebElement) driver.findElement(By.id("test1"));
   RenderedWebElement img2 = (RenderedWebElement) driver.findElement(By.id("test2"));
   img2.dragAndDropOn(img1);
   assertEquals(img1.getLocation(), img2.getLocation());
 }
示例#2
0
  @Test
  public void testShouldCaptureScreenshotAtIFramePageAfterSwitching() throws Exception {
    driver.get(appServer.whereIs("screen/screen_iframes.html"));

    driver.switchTo().frame(driver.findElement(By.id("iframe1")));

    tempFile = screenshoter.getScreenshotAs(OutputType.FILE);
    assertTrue(tempFile.exists());
    assertTrue(tempFile.length() > 0);

    BufferedImage screenshot = (BufferedImage) getImage(tempFile);
    assertTrue(screenshot != null);

    Set<String> expectedColors = getExpectedColors(0x0F0F0F, 1000, 6, 6);
    expectedColors.addAll(getExpectedColors(0xDFDFDF, 1000, 6, 6));

    Set<String> actualColors = new HashSet<String>();
    try {
      actualColors = getColors(screenshot, 5, 5);
    } catch (IOException e) {
      fail("Invalid screenshot image");
    }

    compareColors(expectedColors, actualColors);
  }
示例#3
0
 @JavascriptEnabled
 @Ignore({HTMLUNIT, CHROME, SELENESE})
 public void testElementInDiv() {
   driver.get(dragAndDropPage);
   RenderedWebElement img = (RenderedWebElement) driver.findElement(By.id("test3"));
   Point expectedLocation = img.getLocation();
   drag(img, expectedLocation, 100, 100);
   assertEquals(expectedLocation, img.getLocation());
 }
示例#4
0
  @JavascriptEnabled
  @Ignore({HTMLUNIT, IE, CHROME, SELENESE})
  public void testDragTooFar() {
    driver.get(dragAndDropPage);
    RenderedWebElement img = (RenderedWebElement) driver.findElement(By.id("test1"));
    //        Point expectedLocation = img.getLocation();

    img.dragAndDropBy(Integer.MIN_VALUE, Integer.MIN_VALUE);
    assertEquals(new Point(0, 0), img.getLocation());

    img.dragAndDropBy(Integer.MAX_VALUE, Integer.MAX_VALUE);
    // We don't know where the img is dragged to , but we know it's not too
    // far, otherwise this function will not return for a long long time
  }
示例#5
0
 @JavascriptEnabled
 @Ignore({HTMLUNIT, CHROME, SELENESE})
 public void testDragAndDrop() throws Exception {
   driver.get(dragAndDropPage);
   RenderedWebElement img = (RenderedWebElement) driver.findElement(By.id("test1"));
   Point expectedLocation = img.getLocation();
   drag(img, expectedLocation, 150, 200);
   assertEquals(expectedLocation, img.getLocation());
   driver.manage().setSpeed(Speed.SLOW);
   drag(img, expectedLocation, -50, -25);
   assertEquals(expectedLocation, img.getLocation());
   driver.manage().setSpeed(Speed.MEDIUM);
   drag(img, expectedLocation, 0, 0);
   assertEquals(expectedLocation, img.getLocation());
   driver.manage().setSpeed(Speed.FAST);
   drag(img, expectedLocation, 1, -1);
   assertEquals(expectedLocation, img.getLocation());
 }
示例#6
0
  @JavascriptEnabled
  @Ignore({HTMLUNIT, IE, CHROME, SELENESE})
  public void testShouldAllowUsersToDragAndDropToElementsOffTheCurrentViewPort() {
    driver.get(dragAndDropPage);

    JavascriptExecutor js = (JavascriptExecutor) driver;
    Long height = (Long) js.executeScript("return window.outerHeight;");
    Long width = (Long) js.executeScript("return window.outerWidth;");
    js.executeScript("window.resizeTo(300, 300);");

    try {
      driver.get(dragAndDropPage);
      RenderedWebElement img = (RenderedWebElement) driver.findElement(By.id("test3"));
      Point expectedLocation = img.getLocation();
      drag(img, expectedLocation, 100, 100);
      assertEquals(expectedLocation, img.getLocation());
    } finally {
      js.executeScript("window.resizeTo(arguments[0], arguments[1]);", width, height);
    }
  }
示例#7
0
 public int getElementCount(String locator) {
   List elementsFound = driver.findElements(By.xpath(locator));
   return elementsFound.size();
 }