Create Test Automation HTML reports with Java + Selenium Webdriver
As the name suggests the idea is to create a neat and classy html report that has all the data and the links to your screenshots.
Easy to Read + Clean and classy + Apt data + Links to your screenshots
The easiest way to create reports in any test automation framework. that uses Java is to have separate functions for:
- The Header
- The Data + Footer
You might also want to have a separate function for the footer.
Some sample reports that can be an inspiration:
https://www.qfs.de/en/qftest/report.html
http://www.telerik.com/clientsfiles/258892_TestReport.JPG?sfvrsn=0
http://thucydideswebtestsdotcom.files.wordpress.com/2013/01/new-reporting.png
Html Color codes: http://www.computerhope.com/htmcolor.htm
And here is the code that is reusable:
public void testHeader(String testCaseName) throws IOException{
Date d = new Date();
String date=d.toString().replaceAll(" ", "_");
date=date.replaceAll(":", "_");
date=date.replaceAll("\\+", "_");
result_FolderName="Reports"+"_"+date;
new File("TestReports\\"+result_FolderName).mkdirs();
File file3=new File(System.getProperty("user.dir")+"\\Screenshots\\");
File file5=new File(System.getProperty("user.dir")+"\\TestReports\\"+result_FolderName+"\\" );
FileUtils.copyDirectory(file3,file5);
Properties CONFIG = new Properties();
FileInputStream fs = new FileInputStream(System.getProperty("user.dir")+ "\\src\\com\\PROJECT\\selenium\\properties\\configuration.properties");
CONFIG.load(fs);
String environment=CONFIG.getProperty("environment");
// create results html page
currentTestCase= testCaseName;
String indexHtmlPath="TestReports\\"+result_FolderName+"\\"+currentTestCase+".html";
new File(indexHtmlPath).createNewFile();
FileWriter fstream = new FileWriter(indexHtmlPath);
BufferedWriter out = new BufferedWriter(fstream);
out.write(" Automation Test Report Summary
Automation Test Report Summary
Run Date | "); |
out.write(d.toString());
out.write("
Run Environment
");
out.write(environment);
out.write("
Test Suite Name
");
out.write("Suite_One");
out.write("
Test Case Name
");
out.write(currentTestCase);
out.write("
Report
");Step Number | Test Step Description | Test Data | Test Result | Result Description |
out.write("
");
out.close();
}
public void testReport(String stepNo, String description,String testdata,String result) throws IOException{
String indexHtmlPath="TestReports\\"+result_FolderName+"\\"+currentTestCase+".html";
FileWriter fileWritter = new FileWriter(indexHtmlPath,true);
BufferedWriter out_test_steps = new BufferedWriter(fileWritter);
out_test_steps.write("
");
String data=result;
out_test_steps.write("
"+stepNo+"
");
"+stepNo+"
");
out_test_steps.write("
"+description+"
");
"+description+"
");
out_test_steps.write("
"+testdata+"
");
"+testdata+"
");
if((data.startsWith("Pass") || data.startsWith("PASS")))
else if((data.startsWith("Fail") || data.startsWith("FAIL"))){
}
out_test_steps.write("
"+data+"
");
"+data+"
");
out_test_steps.write("
out_test_steps.write("
");
out_test_steps.close();
}
Hello,
ReplyDeleteThe Article on Create Test Automation HTML reports with Java along with Selenium Webdriver is nice give detail information about it.Thanks for Sharing the information about Testing Automation with Selenium Web Driver.Thanks for Sharing the information about it.mobile application testing