Best way to take screenshots of tests in Selenium 2?

后端 未结 13 2158
别跟我提以往
别跟我提以往 2020-11-28 04:29

I need a way to take screenshots of my functional tests. Right now I\'m using Selenium 2 with C# bindings. I pretty much want to take a screenshot at the end of the test to

13条回答
  •  野性不改
    2020-11-28 05:00

    JAVA

    protected void fullPageScreenshot(String testname) {
                String timeStamp = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss").format(Calendar.getInstance().getTime());
                String imageName = testname + "-" + timeStamp + ".png";
                Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(2000))
                        .takeScreenshot(DriverManager.getDriver());
                try {
                    ImageIO.write(screenshot.getImage(), "PNG", new File("./FullPage_Screenshots/" + imageName));
                } catch (Exception e) {
                    System.out.println("Capturing FullPage Screenshot failed");
                }
            }
    

    use Ashot library to take fullpage screenshots - even where pages needs to be scrolled https://mvnrepository.com/artifact/ru.yandex.qatools.ashot/ashot/1.5.4

提交回复
热议问题