src/main/java/com/github/webdriverextensions/Bot.java
/**
     * Takes a full-page screenshot and saves it as a file in a directory called {@code screenshots}.
     * A custom path to the directory where the screenshots are saved can be set by setting
     * the system property {@code webdriverextensions.screenshotspath}.
     *
     * @param fileName the filename of the screenshot file without the file extension
     */
Takes a full-page screenshot and saves it as a file in a directory called  screenshots.
A custom path to the directory where the screenshots are saved can be set by setting
the system property  webdriverextensions.screenshotspath.

@param fileName the filename of the screenshot file without the file extension
Takes a full - page screenshot and saves it as a file in a directory called screenshots . A custom path to the directory where the screenshots are saved can be set by setting the system property webdriverextensions . screenshotspath . @param fileName the filename of the screenshot file without the file extension
public static void takeFullPageScreenshot(String fileName) {
        Dimension windowSize = new Dimension((int)(long)executeJavascript("return window.innerWidth;"),
                (int)(long)executeJavascript("return window.innerHeight;"));
        int lastHeight = 0;
        while (lastHeight != BotUtils.renderedPageHeight()) {
            lastHeight = (int) BotUtils.renderedPageHeight();
            executeJavascript("window.scrollBy(0," + windowSize.height + ")");
            waitForPageToLoad(); 
            waitFor(0.5, TimeUnit.SECONDS); 
        }
        int totalPageHeight = lastHeight;
        executeJavascript("window.scrollBy(0,-999999999)");
        List<BufferedImage> imageParts = new ArrayList<>();
        int lastImageEnd = 0;
        while(lastImageEnd < totalPageHeight) {
            byte[] bytes = ((TakesScreenshot) driver()).getScreenshotAs(OutputType.BYTES);
            try {
                imageParts.add(ImageIO.read(new ByteArrayInputStream(bytes)));
            } catch (IOException ex) {
            }
            executeJavascript("window.scrollBy(0," + windowSize.height + ")");
            lastImageEnd += windowSize.height;
        }
        BufferedImage finalImage = new BufferedImage(
                windowSize.width,
                totalPageHeight,
                BufferedImage.TYPE_INT_RGB);
        for(int i=0; i<imageParts.size() - 1; ++i) {
            finalImage.createGraphics().drawImage(imageParts.get(i), 0, i*windowSize.height, null);
        }
        BufferedImage lastImage = imageParts.get(imageParts.size()-1);
        finalImage.createGraphics().drawImage(lastImage, 0, finalImage.getHeight() - windowSize.height, null);
        String filePath = getScreenshotFilePath(fileName);
        File file = new File(filePath);
        file.mkdirs(); 
        try {
            ImageIO.write(finalImage, "png", file);
        } catch (IOException ex) {
            throw new WebDriverExtensionException("Failed to save full-page screenshot to " + quote(filePath), ex);
        }
    }
public static void takeFullPageScreenshot ( String fileName ) { Dimension windowSize = new Dimension ( ( int ) ( long ) executeJavascript ( "return window.innerWidth;" ) , ( int ) ( long ) executeJavascript ( "return window.innerHeight;" ) ) ; int lastHeight = 0 ; while ( lastHeight != BotUtils . renderedPageHeight ( ) ) { lastHeight = ( int ) BotUtils . renderedPageHeight ( ) ; executeJavascript ( "window.scrollBy(0," + windowSize . height + ")" ) ; waitForPageToLoad ( ) ; waitFor ( 0.5 , TimeUnit . SECONDS ) ; } int totalPageHeight = lastHeight ; executeJavascript ( "window.scrollBy(0,-999999999)" ) ; List < BufferedImage > imageParts = new ArrayList < > ( ) ; int lastImageEnd = 0 ; while ( lastImageEnd < totalPageHeight ) { byte [ ] bytes = ( ( TakesScreenshot ) driver ( ) ) . getScreenshotAs ( OutputType . BYTES ) ; try { imageParts . add ( ImageIO . read ( new ByteArrayInputStream ( bytes ) ) ) ; } catch ( IOException ex ) { } executeJavascript ( "window.scrollBy(0," + windowSize . height + ")" ) ; lastImageEnd += windowSize . height ; } BufferedImage finalImage = new BufferedImage ( windowSize . width , totalPageHeight , BufferedImage . TYPE_INT_RGB ) ; for ( int i = 0 ; i < imageParts . size ( ) - 1 ; ++ i ) { finalImage . createGraphics ( ) . drawImage ( imageParts . get ( i ) , 0 , i * windowSize . height , null ) ; } BufferedImage lastImage = imageParts . get ( imageParts . size ( ) - 1 ) ; finalImage . createGraphics ( ) . drawImage ( lastImage , 0 , finalImage . getHeight ( ) - windowSize . height , null ) ; String filePath = getScreenshotFilePath ( fileName ) ; File file = new File ( filePath ) ; file . mkdirs ( ) ; try { ImageIO . write ( finalImage , "png" , file ) ; } catch ( IOException ex ) { throw new WebDriverExtensionException ( "Failed to save full-page screenshot to " + quote ( filePath ) , ex ) ; } }
Takes a full-page screenshot and saves it as a file in a directory called {@code screenshots}.
Takes a full - page screenshot and saves it as a file in a directory called { @code screenshots } .
// get inner window size // driver().manage().window().getSize() doesn't work, because it returns // whole window size, with tab bars, scrolls etc. // scroll through whole page to render all it's content // doesn't wait for rendering for some reason // simple hard coded wait will work in most cases // go back to the top of window // make screenshot of current viewport, then scroll, then make // scrennshot etc. until the of the rendered page // bytes must be well formet at this point // scroll down by exactly one screenshot height // at the bottom of the page, there may (and most likely will) be some // overlapping of last 2 screenshots // this section fixes that overlapping // final image that will be stored in file // merge subImages into one. // omit last image that may overlap // make an offset for last image // make target direcory tree if doesn't exists