I need some help attaching a screenshot for failure test cases in ReportNG. Can some one explain me how exactly this is done. I'm new to Selenium and Java. I am using Maven as a build tool.
How to attach a Screenshot in ReportNG Test
3.1k views Asked by patp At
3
There are 3 answers
1
On
You can use below script and call the method in every class where ever you required.
public void screenCapture() throws IOException{
System.setProperty("org.uncommons.reportng.escape-output", "false");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
String Path = "E:\\Automation\\testproject\\Screenshots\\";
File screenshotName = new File(Path +driver.getTitle()+".png");
//Now add screenshot to results by copying the file
FileUtils.copyFile(scrFile, screenshotName);
Reporter.log("<br> <img src='"+screenshotName+"' height='100' width='100' /><br>");
Reporter.log("<a href="+screenshotName+"></a>");
{
Once you have taken a screenshot and stored at some location, you can insert it as a link in the test report as the testng report is a html document.
URL - location on either local or network drive