protected void takeScreenshot(String screenshotName) throws IOException { try { ImageRecognition.takeScreenshot(screenshotName, screenshotsFolder, platform); } catch (Exception e) { File scrFile = driver.getScreenshotAs(OutputType.FILE); String screenshotFile = screenshotsFolder + screenshotName + ".png"; String screenShotFilePath = System.getProperty("user.dir") + "/" + screenshotFile; File testScreenshot = new File(screenShotFilePath); FileUtils.copyFile(scrFile, testScreenshot); logger.info("Screenshot stored to {}", testScreenshot.getAbsolutePath()); return; } }
private File screenshot(String name) { logger.info("Taking screenshot..."); File scrFile = getDriver().getScreenshotAs(OutputType.FILE); try { File testScreenshot = new File(name); FileUtils.copyFile(scrFile, testScreenshot); logger.info("Screenshot saved as " + testScreenshot.getAbsolutePath()); return testScreenshot; } catch (IOException e) { logger.error(e.getMessage(), e); } return null; }
/** * Convenience method that takes a screenshot of the device and returns a BufferedImage for further processing. * @return screenshot from the device as BufferedImage */ public BufferedImage takeScreenshot() { Debug.setDebugLevel(3); File scrFile = driver.getScreenshotAs(OutputType.FILE); BufferedImage bufferedImage = null; try { bufferedImage = ImageIO.read(scrFile); } catch (IOException e) { e.printStackTrace(); } return bufferedImage; }
/** * @author wasiq.bhamla * @since 01-May-2017 8:24:34 PM * @param path */ private void captureScreenshot (final String path) { final String msg = "Capturing screenshot and saving at [%s]..."; log.info (format (msg, path)); try { final File srcFiler = this.driver.getScreenshotAs (OutputType.FILE); copyFile (srcFiler, path); } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); } }
screenShot = driver.getScreenshotAs(OutputType.FILE); }else{ String fileName = ConfigUtil.getRootDir() + File.separator +"del.png";
/** * Makes fullsize screenshot using javascript (May not work properly with * popups and active js-elements on the page) * * @param driver * - webDriver. * @param augmentedDriver * - webDriver. * @exception IOException * * @return screenshot image */ private static BufferedImage takeFullScreenshot(WebDriver driver, WebDriver augmentedDriver) throws Exception { BufferedImage screenShot; if (driver.getClass().toString().contains("java_client")) { // Mobile Native app File screenshot = ((AppiumDriver<?>) driver).getScreenshotAs(OutputType.FILE); screenShot = ImageIO.read(screenshot); } else if (Configuration.getDriverType().equals(SpecialKeywords.MOBILE)) { // Mobile web screenShot = ImageIO.read(((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE)); } else { // regular web ru.yandex.qatools.ashot.Screenshot screenshot = new AShot() .shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(augmentedDriver); screenShot = screenshot.getImage(); } return screenShot; }