Method will create the screen shot when the test fails.
@Override
public void onTestFailure(ITestResult result) {
String workingDirectory = System.getProperty("user.dir");
String fileName = workingDirectory + File.separator + "screenshots" + File.separator + result.getMethod().getMethodName() + "().png";//filename
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(fileName ));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Reporter.log("<a href=\"" + fileName + "\"> Clickhere </a>" );
Reporter.setCurrentTestResult(null);
}
In testng-results.xsl add the below text highlighted in red
---------------------------------------------------------------------------------------
<!-- Reporter output file -->
<xsl:result-document href="{testng:absolutePath('reporterOutput.html')}" format="xhtml">
<html xmlns="http://www.w3.org/1999/xhtml">
<xsl:call-template name="htmlHead"/>
<body>
<h2>Reporter output</h2>
<xsl:for-each select="reporter-output/line">
<div>
<code>
<xsl:value-of select="." disable-output-escaping="yes"/>
</code>
</div>
</xsl:for-each>
<xsl:call-template name="powered-by"/>
</body>
</html>
</xsl:result-document>
</xsl:template>
This will create link in the XSLT report.