congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
TakesScreenshot
Code IndexAdd Tabnine to your IDE (free)

How to use
TakesScreenshot
in
org.openqa.selenium

Best Java code snippets using org.openqa.selenium.TakesScreenshot (Showing top 20 results out of 909)

origin: selenide/selenide

protected File takeScreenshotInMemory(TakesScreenshot driver) {
 try {
  return driver.getScreenshotAs(FILE);
 }
 catch (Exception e) {
  log.log(SEVERE, "Failed to take screenshot in memory", e);
  return null;
 }
}
origin: apache/geode

private void takeScreenshot(String screenshotName) {
 WebDriver driver = this.webDriverSupplier.get();
 if (driver instanceof TakesScreenshot) {
  File tempFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
  try {
   File screenshot = new File("build/screenshots/" + screenshotName + ".png");
   FileUtils.copyFile(tempFile, screenshot);
   System.err.println("Screenshot saved to: " + screenshot.getCanonicalPath());
  } catch (IOException e) {
   throw new Error(e);
  }
 }
}
origin: selenide/selenide

protected File takeScreenshotImage(Config config, TakesScreenshot driver, String fileName) {
 try {
  File scrFile = driver.getScreenshotAs(FILE);
  File imageFile = new File(config.reportsFolder(), fileName + ".png");
  try {
   copyFile(scrFile, imageFile);
  }
  catch (IOException e) {
   log.log(SEVERE, "Failed to save screenshot to " + imageFile, e);
  }
  return imageFile;
 }
 catch (WebDriverException e) {
  log.log(SEVERE, "Failed to take screenshot to " + fileName + " because of " + e);
  return null;
 }
}
origin: cloudfoundry/uaa

public static void takeScreenShot(String prefix, WebDriver webDriver) {
  File scrFile = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
  try {
    SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd-HHmmss.SSS");
    String now = format.format(new Date(System.currentTimeMillis()));
    FileUtils.copyFile(scrFile, new File("build/reports/", prefix + now + ".png"));
  } catch (IOException e) {
    e.printStackTrace();
  }
}
origin: galenframework/galen

public static File takeScreenshot(WebDriver driver) throws IOException {
  File file = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
  if (GalenConfig.getConfig().shouldAutoresizeScreenshots()) {
    BufferedImage image = Rainbow4J.loadImage(file.getAbsolutePath());
    File newFile = File.createTempFile("screenshot", ".png");
    image = GalenUtils.resizeScreenshotIfNeeded(driver, image);
    Rainbow4J.saveImage(image, newFile);
    return newFile;
  }
  else return file;
}

origin: galenframework/galen

public static File makeFullScreenshot(WebDriver driver) throws IOException, InterruptedException {
  byte[] bytes = ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
  BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes));
  int capturedWidth = image.getWidth();
      scroll += scrollOffset;
      scrollVerticallyTo(driver, scroll);
      BufferedImage nextImage = ImageIO.read(new ByteArrayInputStream(((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES)));
      g2dTile.drawImage(nextImage, 0, (i+1) * capturedHeight, null);
      scroll += scrollOffset;
      scrollVerticallyTo(driver, scroll);
      BufferedImage nextImage = ImageIO.read(new ByteArrayInputStream(((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES)));
      BufferedImage lastPart = nextImage.getSubimage(0, nextImage.getHeight() - (int)(((double)leftover) * devicePixelRatio), nextImage.getWidth(), leftover);
      g2dTile.drawImage(lastPart, 0, times * capturedHeight, null);
origin: selenide/selenide

private BufferedImage takeScreenshotAsImage(WebDriver webdriver, WebElement element) {
 if (!(webdriver instanceof TakesScreenshot)) {
  log.warning("Cannot take screenshot because browser does not support screenshots");
  return null;
 }
 byte[] screen = ((TakesScreenshot) webdriver).getScreenshotAs(OutputType.BYTES);
 Point elementLocation = element.getLocation();
 try {
  BufferedImage img = ImageIO.read(new ByteArrayInputStream(screen));
  int elementWidth = element.getSize().getWidth();
  int elementHeight = element.getSize().getHeight();
  if (elementWidth > img.getWidth()) {
   elementWidth = img.getWidth() - elementLocation.getX();
  }
  if (elementHeight > img.getHeight()) {
   elementHeight = img.getHeight() - elementLocation.getY();
  }
  return img.getSubimage(elementLocation.getX(), elementLocation.getY(), elementWidth, elementHeight);
 }
 catch (IOException e) {
  log.log(SEVERE, "Failed to take screenshot of " + element, e);
  return null;
 }
 catch (RasterFormatException e) {
  log.warning("Cannot take screenshot because element is not displayed on current screen position");
  return null;
 }
}
origin: cloudfoundry/uaa

public void debugPage(String className, String description) {
  TakesScreenshot takesScreenshot = (TakesScreenshot) browser;
  File scrFile = takesScreenshot.getScreenshotAs(OutputType.FILE);
  File destFile = getDestinationFile(className, description);
  try {
    FileUtils.copyFile(scrFile, destFile);
  } catch (IOException ioe) {
    throw new RuntimeException(ioe);
  }
  File pageSourceFile = getDestinationFile(className, description + ".html");
  String pageSource = browser.getPageSource();
  try {
    FileUtils.write(pageSourceFile, pageSource);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
origin: selenide/selenide

 return null;
byte[] screen = ((TakesScreenshot) webdriver).getScreenshotAs(OutputType.BYTES);
Point iframeLocation = iframe.getLocation();
BufferedImage img;
origin: stackoverflow.com

 public class ScreenshotListener extends RunListener {

  private TakesScreenshot screenshotTaker;

  @Override
  public void testFailure(Failure failure) throws Exception {
    File file = screenshotTaker.getScreenshotAs(OutputType.File);
    // do something with your file
  }

}
origin: org.codelibs.robot/s2robot

@Override
public <X> X getScreenshotAs(final OutputType<X> target)
    throws WebDriverException {
  return ((TakesScreenshot) webDriver).getScreenshotAs(target);
}
origin: org.codelibs.robot/s2-robot

@Override
public <X> X getScreenshotAs(OutputType<X> target)
    throws WebDriverException {
  return ((TakesScreenshot) webDriver).getScreenshotAs(target);
}
origin: stackoverflow.com

 if (driver instanceof TakesScreenshot) {
  TakesScreenshot ts = (TakesScreenshot) driver;
  File screenshotFile = ts.getScreenshotAs(OutputType.FILE);
  //feel free to move or rename the file as you see fit.
}else{ /* unsupported*/ }
origin: qaprosoft/carina

/**
 * Makes screenshot of visible part of the page
 *
 * @param augmentedDriver
 *            - webDriver.
 * @exception IOException
 * 
 * @return screenshot image
 */
private static BufferedImage takeVisibleScreenshot(WebDriver augmentedDriver) throws Exception {
  return ImageIO.read(((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE));
}

origin: io.github.aktoluna/slnarch-core

public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
 if (driver instanceof TakesScreenshot) {
  return ((TakesScreenshot) driver).getScreenshotAs(target);
 }
 throw new UnsupportedOperationException(
   "Underlying driver instance does not support taking screenshots");
}
origin: com.lohika.alp/alp-selenium

@Override
public <X> X getScreenshotAs(OutputType<X> target)
    throws WebDriverException {
  if (driver instanceof TakesScreenshot) {
    return ((TakesScreenshot) driver).getScreenshotAs(target);
  }
  throw new UnsupportedOperationException(
      "Underlying driver instance does not support taking screenshots");
}
origin: org.bitbucket.iamkenos/cissnei-selenium

public Object takeScreenshot(OutputType outputType) {
  try {
    return ((TakesScreenshot) webDriver).getScreenshotAs(outputType);
  } catch (Exception e) {
    LOGGER.error(e.getMessage());
    throw e;
  }
}
origin: stackoverflow.com

private static void snapshotBrowser(TakesScreenshot driver, String screenSnapshotName, File browserFile) {
   try {
     File scrFile = driver.getScreenshotAs(OutputType.FILE);
     log.info("PNG browser snapshot file name: \"{}\"", browserFile.toURI().toString());
     FileUtils.deleteQuietly(browserFile);
     FileUtils.moveFile(scrFile, browserFile);
   } catch (Exception e) {
     log.error("Could not create browser snapshot: " + screenSnapshotName, e);
   }
 }
origin: bonigarcia/selenium-jupiter

void logBase64Screenshot(WebDriver driver, String fileName) {
  try {
    String screenshotBase64 = ((TakesScreenshot) driver)
        .getScreenshotAs(BASE64);
    log.info("Screenshot (in Base64) at the end of {} "
        + "(copy&paste this string as URL in browser to watch it):\r\n"
        + "data:image/png;base64,{}", fileName, screenshotBase64);
  } catch (Exception e) {
    log.trace("Exception getting screenshot in Base64", e);
  }
}
origin: com.twosigma.webtau/webtau-browser

private BufferedImage takeBufferedImage() {
  byte[] screenshotBytes = screenshotTaker.getScreenshotAs(OutputType.BYTES);
  try {
    return ImageIO.read(new ByteArrayInputStream(screenshotBytes));
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
org.openqa.seleniumTakesScreenshot

Javadoc

Indicates a driver that can capture a screenshot and store it in different ways.

Example usage:

 
File screenshotFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); 
String screenshotBase64 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64); 

Most used methods

  • getScreenshotAs
    Capture the screenshot and store it in the specified location.For WebDriver extending TakesScreensho

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (Timer)
  • getExternalFilesDir (Context)
  • setContentView (Activity)
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Runner (org.openjdk.jmh.runner)
  • Top 12 Jupyter Notebook Extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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