How to take ScreenShot using Selenium WebDriver.
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.support.events.EventFiringWebDriver;
public class ReportLib {
/**
* To Get Screen Shot If Test case Fail and
* @throws IOException
*/
public void getsnapShot(String name) throws IOException{
String path="E:\\abc\\xyz\\project1\\TestData\\"+name+".png";
EventFiringWebDriver edriver=new EventFiringWebDriver(Driver.driver);
File srcimg=edriver.getScreenshotAs(OutputType.FILE);
File dstimg=new File(path);
FileUtils.copyFileToDirectory(srcimg, dstimg);
}
}
For Example:
import org.openqa.selenium.OutputType;
import org.openqa.selenium.support.events.EventFiringWebDriver;
public class ReportLib {
/**
* To Get Screen Shot If Test case Fail and
* @throws IOException
*/
public void getsnapShot(String name) throws IOException{
String path="E:\\abc\\xyz\\project1\\TestData\\"+name+".png";
EventFiringWebDriver edriver=new EventFiringWebDriver(Driver.driver);
File srcimg=edriver.getScreenshotAs(OutputType.FILE);
File dstimg=new File(path);
FileUtils.copyFileToDirectory(srcimg, dstimg);
}
}
For Example:
0 comments:
Post a Comment