Screenshots With Test NGXSLT

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

https://groups.google.com/forum/#!

topic/reporty-ng/BQV5z5ALSWc

Hi ,

I have been using testng xslt report generator and I like it very much as it generates very detailed
html report rather than default testng report generator.

I am also one of you who has been looking for the screenshot integration to xslt html report. I
found a quick solution for this and I want to contribute myself to the TestNg Xslt group. 

I just added 3 tags in testng-results.xsl file and made some changes to my code. Please find the
details below. i am attaching the changed testng-results.xsl file here and you can see 3 <!--
Added new tag for screen shots--> comments in that file where my edits exists.

You don't have to change anything in your build.xml or pom.xml  files when you use this testng-
results.xsl file. But only thing is that you need to change your screenshot file name and
screenshots folder to pickup the screenshot from. Lets say if your generating testng-xslt report in
base directory of your project then your screenshot folder be in same directory. See code,

@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);

FileUtils.copyFile(scrFile, new File(fileName ));


}

Folder structure:
This will store your screenshots in Path/to/your/project/screenshots/testmethod1().png   
And your index.html should be in Path/to/your/project/testng-xslt-report/index.html

That's it. You will see your screenshot in your xslt html report in results page

You might also like