Capturing Screenshots

Posted amy2012

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Capturing Screenshots相关的知识,希望对你有一定的参考价值。

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

protected void takeScreenshot(String fileName)
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String path = System.getProperty("user.dir") + "//test-output//screenshots//" + fileName + ".png";
try
FileUtils.copyFile(scrFile, new File(path));
catch (IOException e)
e.printStackTrace();

 

Note: need apache commons io dependency

<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>

以上是关于Capturing Screenshots的主要内容,如果未能解决你的问题,请参考以下文章