public static File captureElementBitmap(WebElement element) throws Exception {

    // Get the WrapsDriver of the WebElement
    WrapsDriver wrapsDriver = (WrapsDriver) element;

    // Get the entire Screenshot from the driver of passed WebElement
    File screen =
        ((TakesScreenshot) wrapsDriver.getWrappedDriver()).getScreenshotAs(OutputType.FILE);

    // Create an instance of Buffered Image from captured screenshot
    BufferedImage img = ImageIO.read(screen);

    // Get the Width and Height of the WebElement using getSize()
    int width = element.getSize().getWidth();
    int height = element.getSize().getHeight();

    // Create a rectangle using Width and Height
    Rectangle rect = new Rectangle(width, height);

    // Get the Location of WebElement in a Point.
    // This will provide X & Y co-ordinates of the WebElement
    Point p = element.getLocation();

    // Create image by for element using its location and size.
    // This will give image data specific to the WebElement
    BufferedImage dest = img.getSubimage(p.getX(), p.getY(), rect.width, rect.height);

    // Write back the image data for element in File object
    ImageIO.write(dest, "png", screen);

    // Return the File object containing image data
    return screen;
  }
Example #2
0
 private void assertOverlayProperties(
     String cell, double width, double height, String paddingLeft) {
   WebElement elementC10 = overlayHelper.getOverlayElement(cell);
   assertEquals(width, elementC10.getSize().width, 1);
   assertEquals(height, elementC10.getSize().height, 1);
   assertEquals(paddingLeft, elementC10.getCssValue("padding-left"));
   // could not compare padding top as it is set in pt and the browsers
   // report it in px
 }
Example #3
0
 /**
  * Checks that the checkMe element's center point coincides with the reference element's center
  * point.
  */
 public static void assertCentered(WebElement reference, WebElement checkMe) {
   Point referenceCenter =
       new Point(
           reference.getLocation().x + reference.getSize().width / 2,
           reference.getLocation().y + reference.getSize().height / 2);
   Point checkMeCenter =
       new Point(
           checkMe.getLocation().x + checkMe.getSize().width / 2,
           checkMe.getLocation().y + checkMe.getSize().height / 2);
   assertEquals(referenceCenter, checkMeCenter);
 }
  /**
   * == Displaying of file format (image, pdf, office) in the File activity (2) == Test case ID:
   * 77112 Step 1: - Connect to Intranet - Go to CE and Upload a file: image, pdf or office document
   * (except personal document drive) - Go back intranet home page Verify by comparison width heigh
   * and width: The orientation of the file can be portrait or landscape following its original
   * orientation
   */
  @Test
  public void test08_DisplayingOfFileFormatImagePdfOfficeInTheFileActivity2() {
    // Declare variable
    String file1 = "portrait08.jpg";
    String file2 = "landscape08.jpg";
    By elementfile1 = By.linkText(file1);
    By elementfile2 = By.linkText(file2);

    // Go to SE
    navToolBar.goToSiteExplorer();

    // Upload a file: image, pdf or office document (except personal document drive)
    ecms.uploadFile("TestData/" + file1);
    ecms.uploadFile("TestData/" + file2);

    // Back to the Home page
    info("-- Back to the Home page --");
    navToolBar.goToHomePage();

    // - The File activity is displayed in the activity stream
    info("-- A File activity is added to the activity stream --");
    activity.checkInforAfterAddingDocument(file1, "", "File", "", "", "", "", "");
    activity.checkInforAfterAddingDocument(file2, "", "File", "", "", "", "", "");

    // - The orientation of the file can be portrait or landscape following its original orientation
    WebElement element =
        waitForAndGetElement(By.xpath(ELEMENT_GET_URL_IMAGE.replace("${name}", file1)));
    String src = element.getAttribute("src");
    driver.navigate().to(src);
    WebElement image =
        waitForAndGetElement(By.xpath(ELEMENT_GET_URL_IMAGE.replace("${name}", src)));
    int height = image.getSize().getHeight();
    assert (height == 300);

    driver.navigate().back();
    element = waitForAndGetElement(By.xpath(ELEMENT_GET_URL_IMAGE.replace("${name}", file2)));
    src = element.getAttribute("src");
    driver.navigate().to(src);
    image = waitForAndGetElement(By.xpath(ELEMENT_GET_URL_IMAGE.replace("${name}", src)));
    height = image.getSize().getHeight();
    assert (height == 89);
    driver.navigate().back();

    /*Clear data*/
    info("-- Clear data --");
    navToolBar.goToSiteExplorer();
    cMenu.deleteData(elementfile1);
    cMenu.deleteData(elementfile2);
  }
  public static int getElementWidth(WebDriver webDriver, String locator) {
    WebElement webElement = getWebElement(webDriver, locator, "1");

    Dimension dimension = webElement.getSize();

    return dimension.getWidth();
  }
  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;
    }
  }
  /**
   * Crops the image to show only the element. If the element is partly off screen, crops to show
   * the part of the element which is in the screenshot
   *
   * @param element the element to retain in the screenshot
   * @param fullScreen the full screen image
   * @param isIE8 true if the browser is IE8
   * @return
   * @throws IOException
   */
  public static BufferedImage cropToElement(
      WebElement element, BufferedImage fullScreen, boolean isIE8) throws IOException {
    Point loc = element.getLocation();
    Dimension size = element.getSize();
    int x = loc.x, y = loc.y;
    int w = size.width;
    int h = size.height;

    if (isIE8) {
      // IE8 border...
      x += 2;
      y += 2;
    }
    if (x >= 0 && x < fullScreen.getWidth()) {
      // X loc on screen
      // Get the part of the element which is on screen
      w = Math.min(fullScreen.getWidth() - x, w);
    } else {
      throw new IOException("Element x is outside the screenshot (x: " + x + ", y: " + y + ")");
    }

    if (y >= 0 && y < fullScreen.getHeight()) {
      // Y loc on screen
      // Get the part of the element which is on screen
      h = Math.min(fullScreen.getHeight() - y, h);
    } else {
      throw new IOException("Element y is outside the screenshot (x: " + x + ", y: " + y + ")");
    }

    return fullScreen.getSubimage(x, y, w, h);
  }
  @JavascriptEnabled
  @Test
  @Ignore(
      value = {SAFARI, MARIONETTE},
      reason = "Advanced mouse actions only implemented in rendered browsers",
      issues = {4136})
  @NotYetImplemented(HTMLUNIT)
  @NoDriverAfterTest
  public void testCanMoveOverAndOutOfAnElement() {
    driver.get(pages.mouseOverPage);

    WebElement greenbox = driver.findElement(By.id("greenbox"));
    WebElement redbox = driver.findElement(By.id("redbox"));
    Dimension size = redbox.getSize();

    new Actions(driver).moveToElement(greenbox, 1, 1).perform();

    assertEquals(
        Colors.GREEN.getColorValue(), Color.fromString(redbox.getCssValue("background-color")));

    new Actions(driver).moveToElement(redbox).perform();
    assertEquals(
        Colors.RED.getColorValue(), Color.fromString(redbox.getCssValue("background-color")));

    // IE8 (and *only* IE8) requires a move of 2 pixels. All other browsers
    // would be happy with 1.
    new Actions(driver).moveToElement(redbox, size.getWidth() + 2, size.getHeight() + 2).perform();
    assertEquals(
        Colors.GREEN.getColorValue(), Color.fromString(redbox.getCssValue("background-color")));
  }
  private void initParams() {
    WebElement dateSlot = getDriver().findElement(By.className("v-datecellslot"));
    int dateSlotWidth = dateSlot.getSize().getWidth();
    noOverlapWidth = dateSlotWidth;
    oneOverlapWidth = dateSlotWidth / 2;
    twoOverlapsWidth = dateSlotWidth / 3;

    Comparator<WebElement> startTimeComparator =
        new Comparator<WebElement>() {
          @Override
          public int compare(WebElement e1, WebElement e2) {
            int e1Top = e1.getLocation().getY();
            int e2Top = e2.getLocation().getY();
            return e1Top - e2Top;
          }
        };

    List<WebElement> eventElements =
        getDriver().findElements(By.className("v-calendar-event-content"));
    Collections.sort(eventElements, startTimeComparator);
    firstEvent = eventElements.get(0);
    secondEvent = eventElements.get(1);
    thirdEvent = eventElements.get(2);

    List<WebElement> resizeBottomElements =
        getDriver().findElements(By.className("v-calendar-event-resizebottom"));
    Collections.sort(resizeBottomElements, startTimeComparator);
    firstEventBottomResize = resizeBottomElements.get(0);
    secondEventBottomResize = resizeBottomElements.get(1);
    thirdEventBottomResize = resizeBottomElements.get(2);
  }
Example #10
0
  public String checkAddedQTY() {

    while (miniCartQTY1.getSize() == null) allPage.sendKeys(Keys.F5);
    // element appear after text READY is presented

    return (miniCartQTY.getText());
  }
Example #11
0
 public void takeScreenShotOfElementOnFailureSecond() throws IOException {
   // Get entire page screenshot
   File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
   BufferedImage fullImg = ImageIO.read(screenshot);
   // Get the location of element on the page
   Point point = element.getLocation();
   // Get width and height of the element
   int eleWidth = element.getSize().getWidth();
   int eleHeight = element.getSize().getHeight();
   // Crop the entire page screenshot to get only element screenshot
   BufferedImage eleScreenshot =
       fullImg.getSubimage(point.getX(), point.getY(), eleWidth, eleHeight);
   ImageIO.write(eleScreenshot, "png", screenshot);
   // Copy the element screenshot to disk
   FileUtils.copyFile(
       screenshot, new File("/home/dima/Downloads/-autotest-data/Element_Screenshots/"));
 }
 public static void ScreenCapture() throws IOException {
   File file = new File("C:\\Selenium\\jenkindemo\\src\\objectRepositry\\Products_PageObjects");
   FileInputStream input = new FileInputStream(file);
   Properties prop = new Properties();
   prop.load(input);
   WebElement element = dr.findElement(By.xpath(prop.getProperty("ScreenElement")));
   File scrFile = ((TakesScreenshot) dr).getScreenshotAs(OutputType.FILE);
   BufferedImage fullImg = ImageIO.read(scrFile);
   Point point = element.getLocation();
   int eleWidth = element.getSize().getWidth();
   int eleHeight = element.getSize().getHeight();
   BufferedImage eleScreenshot =
       fullImg.getSubimage(point.getX(), point.getY(), eleWidth, eleHeight);
   ImageIO.write(eleScreenshot, "png", scrFile);
   String filename = "Screenshot" + System.currentTimeMillis();
   FileUtils.copyFile(scrFile, new File("c:\\sel_screen\\" + filename + ".png"));
 }
Example #13
0
 /**
  * Returns Locations of input element.
  *
  * @see Locations
  */
 public static Locations getLocations(WebElement root) {
   Point topLeft = root.getLocation();
   Dimension dimension = root.getSize();
   Point topRight = topLeft.moveBy(dimension.getWidth(), 0);
   Point bottomRight = topRight.moveBy(0, dimension.getHeight());
   Point bottomLeft = topLeft.moveBy(0, dimension.getHeight());
   return new Locations(topLeft, topRight, bottomLeft, bottomRight);
 }
Example #14
0
 /**
  * Returns Locations of input element.
  *
  * @see Locations
  */
 public static Locations getLocations(WebElement root) {
   Preconditions.checkNotNull(root, "The element cannot be null.");
   Point topLeft = root.getLocation();
   Dimension dimension = root.getSize();
   Point topRight = topLeft.moveBy(dimension.getWidth(), 0);
   Point bottomRight = topRight.moveBy(0, dimension.getHeight());
   Point bottomLeft = topLeft.moveBy(0, dimension.getHeight());
   return new Locations(topLeft, topRight, bottomLeft, bottomRight);
 }
Example #15
0
  public void shoot(WebElement element) throws IOException {
    //        try {
    //            driver = new Augmenter().augment(driver);
    //        } catch (Exception ignored) {
    //        }
    File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

    Point p = element.getLocation();
    int width = element.getSize().getWidth();
    int height = element.getSize().getHeight();
    Rectangle rect = new Rectangle(width, height);
    BufferedImage img = null;
    img = ImageIO.read(screen);
    BufferedImage dest = img.getSubimage(p.getX(), p.getY(), rect.width, rect.height);
    ImageIO.write(dest, "png", screen);

    FileUtils.copyFile(screen, new File(screenshotFolder + System.nanoTime() + ".png"));
  }
  private void assertWidths(
      int firstEventExpectedWidth, int secondEventExpectedWidth, int thirdEventExpectedWidth) {
    int widthTolerance = 5;
    String errorMessage = "Wrong event width after resizing, expected [%d] (+/-%d), obtained [%d]";

    int actualWidth = firstEvent.getSize().getWidth();
    int expectedWidth = firstEventExpectedWidth;
    Assert.assertTrue(
        String.format(errorMessage, expectedWidth, widthTolerance, actualWidth),
        isAproximateWidth(actualWidth, expectedWidth, widthTolerance));

    actualWidth = secondEvent.getSize().getWidth();
    expectedWidth = secondEventExpectedWidth;
    Assert.assertTrue(
        String.format(errorMessage, expectedWidth, widthTolerance, actualWidth),
        isAproximateWidth(actualWidth, expectedWidth, widthTolerance));

    actualWidth = thirdEvent.getSize().getWidth();
    expectedWidth = thirdEventExpectedWidth;
    Assert.assertTrue(
        String.format(errorMessage, expectedWidth, widthTolerance, actualWidth),
        isAproximateWidth(actualWidth, expectedWidth, widthTolerance));
  }
Example #17
0
 private boolean isOutsideOfWindow(WebElement tooltip) {
   if (!tooltip.isDisplayed()) {
     return true;
   }
   // The tooltip is shown, at least partially, if
   // its intervals of both horizontal and vertical coordinates
   // overlap those of the window.
   Point topLeft = tooltip.getLocation();
   Dimension tooltipSize = tooltip.getSize();
   Dimension windowSize = driver.manage().window().getSize();
   int xLeft = topLeft.getX();
   int yTop = topLeft.getY();
   int xRight = xLeft + tooltipSize.getWidth() - 1;
   int yBottom = yTop + tooltipSize.getHeight() - 1;
   boolean overlapHorizontally = !(xRight < 0 || xLeft >= windowSize.getWidth());
   boolean overlapVertically = !(yBottom < 0 || yTop >= windowSize.getHeight());
   return !(overlapHorizontally && overlapVertically);
 }
  @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);
  }
  @JavascriptEnabled
  @Test
  @Ignore(
      value = {SAFARI, MARIONETTE},
      reason = "Advanced mouse actions only implemented in rendered browsers",
      issues = {4136})
  @NotYetImplemented(HTMLUNIT)
  // @NoDriverAfterTest
  public void testMoveMouseByOffsetOverAndOutOfAnElement() {
    driver.get(pages.mouseOverPage);

    WebElement greenbox = driver.findElement(By.id("greenbox"));
    WebElement redbox = driver.findElement(By.id("redbox"));
    Dimension size = redbox.getSize();
    Point greenboxPosition = greenbox.getLocation();
    Point redboxPosition = redbox.getLocation();
    int shiftX = redboxPosition.getX() - greenboxPosition.getX();
    int shiftY = redboxPosition.getY() - greenboxPosition.getY();

    new Actions(driver).moveToElement(greenbox, 2, 2).perform();

    assertEquals(
        Colors.GREEN.getColorValue(), Color.fromString(redbox.getCssValue("background-color")));

    new Actions(driver).moveToElement(greenbox, 2, 2).moveByOffset(shiftX, shiftY).perform();
    assertEquals(
        Colors.RED.getColorValue(), Color.fromString(redbox.getCssValue("background-color")));

    new Actions(driver)
        .moveToElement(greenbox, 2, 2)
        .moveByOffset(shiftX, shiftY)
        .moveByOffset(-shiftX, -shiftY)
        .perform();
    assertEquals(
        Colors.GREEN.getColorValue(), Color.fromString(redbox.getCssValue("background-color")));
  }
 @Override
 public Dimension getSize(WebElement element) {
   return element.getSize();
 }
Example #21
0
  public ResultType call() throws Exception {
    WebElement element = getElement();
    response.setValue(element.getSize());

    return ResultType.SUCCESS;
  }
  public double getTargetHeight(WebElement target) {
    Dimension dimension = target.getSize();

    return dimension.getHeight();
  }
  public double getTargetWidth(WebElement target) {
    Dimension dimension = target.getSize();

    return dimension.getWidth();
  }
 /**
  * return the size of the elements
  *
  * @return
  */
 public Dimension getSize() {
   return webElement.getSize();
 }