currently I am taking screenshots of my test failures this way:
@AfterMethod(alwaysRun=true)
public void catchExceptions(ITestResult result){
Calendar calendar = Calendar.getInstance();
SimpleDateFormat formater = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss");
String methodName = result.getName();
if(!result.isSuccess()){
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File((String) PathConverter.convert("failure_screenshots/"+methodName+"_"+formater.format(calendar.getTime())+".png")));
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
Can I include my own screenshots into the TestNG report link or pic? If yes how?
All I found on that online is the FEST framework. But since I am already taking the screenshots I dont want to use another framework.
Yes, you can include the link to your screenshot in testng report.
You need to call
org.testng.Reporter.log
method to write the hyperlink to the testng report either by annotating your test class or parent of all testclasses with @Listeners({yourListener.class}) or by adding the listener to yourtestng.xml
.You need to first create a Listener class and add it to testng. You can get details for that from testng.org. Search for listener.
Once you create that class, you should write a method in it which overrides the
ontestfailure
method. The code inside this method will be executed whenever testng identifies a failure.You can call your screenshot grabbing method and use
Reporter.log
to put the hyperlink to that screenshot. Then you can find this link under the failed testcases details.