码迷,mamicode.com
首页 > Web开发 > 详细

使用AShot进行网页全页截图

时间:2018-10-30 13:16:32      阅读:524      评论:0      收藏:0      [点我收藏+]

标签:tools   less   man   group   adl   let   home   drive   add   

import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class DemoApplicationTests {

    @Test
    public void contextLoads() throws InterruptedException, IOException {
        System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
        ChromeOptions chromeOptions = new ChromeOptions();
        //设置为 headless 模式 (必须)
        //chromeOptions.addArguments("--headless");
        final WebDriver driver = new ChromeDriver(chromeOptions);

        driver.manage().window().maximize();
        driver.get("https://autohome.com.cn/");

        // Let the user actually see something!
        Thread.sleep(5000);
        BufferedImage bi = new AShot()
                .shootingStrategy(ShootingStrategies.viewportPasting(100))
                .takeScreenshot(driver).getImage();
        ImageIO.write(bi, "png", new File("C:/test.png"));
        driver.quit();
    }

}
<dependency>
    <groupId>ru.yandex.qatools.ashot</groupId>
    <artifactId>ashot</artifactId>
    <version>1.5.2</version>
</dependency>

 

使用AShot进行网页全页截图

标签:tools   less   man   group   adl   let   home   drive   add   

原文地址:https://www.cnblogs.com/haitao-fan/p/9876128.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!