Tabnine Logo
Browser.getViewportHeight
Code IndexAdd Tabnine to your IDE (free)

How to use
getViewportHeight
method
in
com.assertthat.selenium_shutterbug.utils.web.Browser

Best Java code snippets using com.assertthat.selenium_shutterbug.utils.web.Browser.getViewportHeight (Showing top 6 results out of 315)

origin: com.assertthat/selenium-shutterbug

public BufferedImage takeScreenshotScrollVertically() {
  BufferedImage combinedImage = new BufferedImage(this.getViewportWidth(), this.getDocHeight(), BufferedImage.TYPE_INT_ARGB);
  Graphics2D g = combinedImage.createGraphics();
  int verticalIterations = (int) Math.ceil(((double) this.getDocHeight()) / this.getViewportHeight());
  for (int j = 0; j < verticalIterations; j++) {
    this.scrollTo(0, j * this.getViewportHeight());
    wait(scrollTimeout);
    Image image = takeScreenshot();
    g.drawImage(image, 0, this.getCurrentScrollY(), null);
    if(this.getDocHeight() == image.getHeight(null)){
      break;
    }
  }
  g.dispose();
  return combinedImage;
}
origin: com.assertthat/selenium-shutterbug

public BufferedImage takeScreenshotScrollHorizontally() {
  BufferedImage combinedImage = new BufferedImage(this.getDocWidth(), this.getViewportHeight(), BufferedImage.TYPE_INT_ARGB);
  Graphics2D g = combinedImage.createGraphics();
  int horizontalIterations = (int) Math.ceil(((double) this.getDocWidth()) / this.getViewportWidth());
  for (int i = 0; i < horizontalIterations; i++) {
    this.scrollTo(i * this.getViewportWidth(), 0);
    wait(scrollTimeout);
    Image image = takeScreenshot();
    g.drawImage(image, this.getCurrentScrollX(), 0, null);
    if(this.getDocWidth() == image.getWidth(null)){
      break;
    }
  }
  g.dispose();
  return combinedImage;
}
origin: com.assertthat/selenium-shutterbug

public BufferedImage takeScreenshotEntirePageUsingChromeCommand() {
  this.driver = getDriverAfterValidation(this.driver);
  try {
    CommandInfo cmd = new CommandInfo("/session/:sessionId/chromium/send_command_and_get_result", HttpMethod.POST);
    Method defineCommand = HttpCommandExecutor.class.getDeclaredMethod("defineCommand", String.class, CommandInfo.class);
    defineCommand.setAccessible(true);
    defineCommand.invoke(((RemoteWebDriver) this.driver).getCommandExecutor(), "sendCommand", cmd);
  } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
    throw new RuntimeException(e);
  }
  int verticalIterations = (int) Math.ceil(((double) this.getDocHeight()) / this.getViewportHeight());
  for (int j = 0; j < verticalIterations; j++) {
    this.scrollTo(0, j * this.getViewportHeight());
    wait(scrollTimeout);
  }
  Object metrics = this.evaluate(FileUtil.getJsScript(ALL_METRICS));
  this.sendCommand("Emulation.setDeviceMetricsOverride", metrics);
  Object result = this.sendCommand("Page.captureScreenshot", ImmutableMap.of("format", "png", "fromSurface", true));
  String base64EncodedPng = (String) ((Map<String, ?>) result).get("data");
  InputStream in = new ByteArrayInputStream(OutputType.BYTES.convertFromBase64Png(base64EncodedPng));
  BufferedImage bImageFromConvert;
  try {
    bImageFromConvert = ImageIO.read(in);
  } catch (IOException e) {
    throw new RuntimeException("Error while converting results from bytes to BufferedImage");
  }
  return bImageFromConvert;
}
origin: assertthat/selenium-shutterbug

public BufferedImage takeScreenshotEntirePageUsingChromeCommand() {
  //should use devicePixelRatio by default as chrome command executor makes screenshot account for that
  Object devicePixelRatio = executeJsScript(DEVICE_PIXEL_RATIO);
  this.devicePixelRatio = devicePixelRatio instanceof Double? (Double)devicePixelRatio: (Long)devicePixelRatio*1.0;
  try {
    CommandInfo cmd = new CommandInfo("/session/:sessionId/chromium/send_command_and_get_result", HttpMethod.POST);
    Method defineCommand = HttpCommandExecutor.class.getDeclaredMethod("defineCommand", String.class, CommandInfo.class);
    defineCommand.setAccessible(true);
    defineCommand.invoke(((RemoteWebDriver) this.driver).getCommandExecutor(), "sendCommand", cmd);
  } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
    throw new RuntimeException(e);
  }
  int verticalIterations = (int) Math.ceil(((double) this.getDocHeight()) / this.getViewportHeight());
  for (int j = 0; j < verticalIterations; j++) {
    this.scrollTo(0, j * this.getViewportHeight());
    wait(scrollTimeout);
  }
  Object metrics = this.evaluate(FileUtil.getJsScript(ALL_METRICS));
  this.sendCommand("Emulation.setDeviceMetricsOverride", metrics);
  Object result = this.sendCommand("Page.captureScreenshot", ImmutableMap.of("format", "png", "fromSurface", true));
  String base64EncodedPng = (String) ((Map<String, ?>) result).get("data");
  InputStream in = new ByteArrayInputStream(OutputType.BYTES.convertFromBase64Png(base64EncodedPng));
  BufferedImage bImageFromConvert;
  try {
    bImageFromConvert = ImageIO.read(in);
  } catch (IOException e) {
    throw new RuntimeException("Error while converting results from bytes to BufferedImage");
  }
  return bImageFromConvert;
}
origin: com.assertthat/selenium-shutterbug

public BufferedImage takeScreenshotEntirePage() {
  final int _docWidth = this.getDocWidth();
  final int _docHeight = this.getDocHeight();
  BufferedImage combinedImage = new BufferedImage(_docWidth, _docHeight, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g = combinedImage.createGraphics();
  int _viewportWidth = this.getViewportWidth();
  int _viewportHeight = this.getViewportHeight();
  final int scrollBarMaxWidth = 40; // this is probably too high, but better to be safe than sorry
  if (_viewportWidth < _docWidth || (_viewportHeight < _docHeight && _viewportWidth - scrollBarMaxWidth < _docWidth))
    _viewportHeight-=scrollBarMaxWidth; // some space for a scrollbar
  if (_viewportHeight < _docHeight)
    _viewportWidth-=scrollBarMaxWidth; // some space for a scrollbar
  int horizontalIterations = (int) Math.ceil(((double) _docWidth) / _viewportWidth);
  int verticalIterations = (int) Math.ceil(((double) _docHeight) / _viewportHeight);
  outer_loop:
  for (int j = 0; j < verticalIterations; j++) {
    this.scrollTo(0, j * _viewportHeight);
    for (int i = 0; i < horizontalIterations; i++) {
      this.scrollTo(i * _viewportWidth, _viewportHeight * j);
      wait(scrollTimeout);
      Image image = takeScreenshot();
      g.drawImage(image, this.getCurrentScrollX(), this.getCurrentScrollY(), null);
      if(_docWidth == image.getWidth(null) && _docHeight == image.getHeight(null)){
        break outer_loop;
      }
    }
  }
  g.dispose();
  return combinedImage;
}
origin: assertthat/selenium-shutterbug

public BufferedImage takeScreenshotEntirePageDefault() {
  final int _docWidth = this.getDocWidth();
  final int _docHeight = this.getDocHeight();
  BufferedImage combinedImage = new BufferedImage(_docWidth, _docHeight, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g = combinedImage.createGraphics();
  int _viewportWidth = this.getViewportWidth();
  int _viewportHeight = this.getViewportHeight();
  final int scrollBarMaxWidth = 40; // this is probably too high, but better to be safe than sorry
  if (_viewportWidth < _docWidth || (_viewportHeight < _docHeight && _viewportWidth - scrollBarMaxWidth < _docWidth))
    _viewportHeight-=scrollBarMaxWidth; // some space for a scrollbar
  if (_viewportHeight < _docHeight)
    _viewportWidth-=scrollBarMaxWidth; // some space for a scrollbar
  int horizontalIterations = (int) Math.ceil(((double) _docWidth) / _viewportWidth);
  int verticalIterations = (int) Math.ceil(((double) _docHeight) / _viewportHeight);
  outer_loop:
  for (int j = 0; j < verticalIterations; j++) {
    this.scrollTo(0, j * _viewportHeight);
    for (int i = 0; i < horizontalIterations; i++) {
      this.scrollTo(i * _viewportWidth, _viewportHeight * j);
      wait(scrollTimeout);
      Image image = takeScreenshot();
      g.drawImage(image, this.getCurrentScrollX(), this.getCurrentScrollY(), null);
      if(_docWidth == image.getWidth(null) && _docHeight == image.getHeight(null)){
        break outer_loop;
      }
    }
  }
  g.dispose();
  return combinedImage;
}
com.assertthat.selenium_shutterbug.utils.webBrowsergetViewportHeight

Popular methods of Browser

  • <init>
  • evaluate
  • executeJsScript
  • getBoundingClientRect
  • getCurrentScrollX
  • getCurrentScrollY
  • getDevicePixelRatio
  • getDocHeight
  • getDocWidth
  • getUnderlyingDriver
  • getViewportWidth
  • scrollTo
  • getViewportWidth,
  • scrollTo,
  • scrollToElement,
  • sendCommand,
  • setScrollTimeout,
  • takeScreenshot,
  • takeScreenshotEntirePage,
  • takeScreenshotEntirePageUsingChromeCommand,
  • wait

Popular in Java

  • Finding current android device location
  • startActivity (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • putExtra (Intent)
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • JFrame (javax.swing)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now