在验证某些关键步骤时,需要截个图来记录一下当时的情况
Webdriver截图时,需要引入
importjava.io.File;importjava.io.IOException;importorg.apache.commons.io.FileUtils;importorg.openqa.selenium.OutputType;import org.openqa.selenium.TakesScreenshot;
截图方法
public static voidsnapshot(TakesScreenshot drivername, String filename)
{//this method will take screen shot ,require two parameters ,one is driver name, another is file name
String currentPath= System.getProperty("user.dir"); //get current work folder
System.out.println(currentPath);
File scrFile=drivername.getScreenshotAs(OutputType.FILE);//Now you can do whatever you need to do with it, for example copy somewhere
try{
System.out.println("save snapshot path is:"+currentPath+"/"+filename);
FileUtils.copyFile(scrFile,new File(currentPath+"\\"+filename));