Exemplo n.º 1
0
  @Test
  public void testNoFocusOnProgrammaticOpen() {

    selectMenuPath(EDIT_ROW_5);

    WebElement focused = getFocusedElement();

    if (BrowserUtil.isIE8(getDesiredCapabilities())) {
      assertEquals("Focus should be in html", "html", focused.getTagName());
    } else if (BrowserUtil.isIE(getDesiredCapabilities())) {
      assertEquals("Focus should be nowhere", null, focused);
    } else {
      // GWT menubar loses focus after clicking a menuitem
      assertEquals("Focus should be in body", "body", focused.getTagName());
    }
  }
Exemplo n.º 2
0
  /**
   * Captures a screenshot of the given screen (if parameter is a driver) or the given element (if
   * the parameter is a WebElement).
   *
   * @param screenshotContext
   * @param capabilities
   * @param isIE8 <code>true</code> if this is IE8, <code>false</code> otherwise
   * @return
   * @throws IOException
   */
  private static BufferedImage getScreenshot(
      TakesScreenshot driver, TakesScreenshot screenshotContext, Capabilities capabilities)
      throws IOException {
    boolean elementScreenshot = (screenshotContext instanceof WebElement);

    if (elementScreenshot && supportsElementScreenshots == null) {
      if (BrowserUtil.isPhantomJS(capabilities)) {
        // PhantomJS will die if you try to detect this...
        supportsElementScreenshots = false;
      } else {
        // Detect if the driver supports element screenshots or not
        try {
          byte[] screenshotBytes = screenshotContext.getScreenshotAs(OutputType.BYTES);
          supportsElementScreenshots = true;
          return ImageIO.read(new ByteArrayInputStream(screenshotBytes));
        } catch (UnsupportedCommandException e) {
          supportsElementScreenshots = false;
        } catch (WebDriverException e) {
          if (e.getCause() instanceof UnsupportedCommandException) {
            supportsElementScreenshots = false;
          } else {
            throw e;
          }
        }
      }
    }

    if (elementScreenshot && !supportsElementScreenshots) {
      // Driver does not support element screenshots, get whole screen
      // and crop
      BufferedImage image =
          ImageIO.read(new ByteArrayInputStream(driver.getScreenshotAs(OutputType.BYTES)));
      return cropToElement((WebElement) screenshotContext, image, BrowserUtil.isIE8(capabilities));
    } else {
      // Element or full screen image
      return ImageIO.read(
          new ByteArrayInputStream(screenshotContext.getScreenshotAs(OutputType.BYTES)));
    }
  }