Skip to main content
Cases
New Case
Knowledge Base
Logout
Configuring ReadyAPI to save Project or TestSuite reports on each test run
Article Type:
Technical Article
Published On:
12/22/17
Product:
SoapUI
Overview
This article shows how to configure ReadyAPI to save Project or TestSuite reports on each test run.
Article
If you want to automatically save a Project or TestSuite report to a hard drive for every run triggered either manually or by an automated task, you can achieve this by using the below script. This script can generate a PDF/Excel/CSV type of report with a unique name (the name includes the current timestamp), which allows saving multiple reports to one folder. To perform this, it is necessary to set up a teardown script of the appropriate projects and test suites.
Here is the script:
import java.text.SimpleDateFormat
import org.apache.commons.io.FilenameUtils
import org.h2.store.fs.FileUtils
import com.eviware.soapui.impl.wsdl.WsdlProject
import com.eviware.soapui.reporting.reports.project.WsdlProjectReport
import com.eviware.soapui.reporting.reports.testsuite.WsdlTestSuiteReport
import com.eviware.soapui.reporting.ReportEngineRegistry
import com.eviware.soapui.reporting.GeneratableReport
import com.eviware.soapui.reporting.engine.jasper.JasperReportEngine
import com.eviware.soapui.reporting.ModelItemReport
import com.eviware.soapui.support.StringUtils
final String REPORTS_FOLDER = 'C:\\Reports'
final String REPORT_FORMAT = 'PDF' // Please specify CSV to get a .csv file
String getCurrentDateTime() {
return new SimpleDateFormat('MM-dd-yyyy hh-mm-ss a').format(new Date())
}
String modifyReportName(String reportFilePath, String reportDisplayName) {
// Please make any desirable modifications of the report name here
String newReportName = String.format('%s [%s]', reportDisplayName, getCurrentDateTime())
// -----
return FilenameUtils.getFullPath(reportFilePath) + newReportName + '.' + FilenameUtils.getExtension(reportFilePath)
}
void renameFile(String oldFilePath, String newFilePath) {
File oldFile = new File(oldFilePath)
File newFile = new File(newFilePath)
oldFile.renameTo(newFile)
}
void exportReport(ModelItemReport modelItemReport, String reportDisplayName, String exportFormat,
String exportDir) {
JasperReportEngine engine = new JasperReportEngine()
List<GeneratableReport> reports = new ArrayList<>()
reports.addAll(engine.getGeneratableReports(modelItemReport))
GeneratableReport[] availableReports = reports.toArray(new GeneratableReport[reports.size()])
try {
if (availableReports.length == 0) {
log.error("Unable to create the \"$reportDisplayName\" report of the \"$exportFormat\" format because there are no available reports.")
return
}
GeneratableReport report = availableReports[0]
String[] exportFormats = new String[1]
exportFormats[0] = exportFormat
String[] exportFileNames = report.generate(modelItemReport.getModelItem().getSettings(), exportFormats, exportDir)
String reportFilePath = exportFileNames.length > 0 ? exportFileNames[0] : null
if (StringUtils.isNullOrEmpty(reportFilePath) || !FileUtils.exists(reportFilePath)) {
log.error("Unable to create the \"$reportDisplayName\" report of the \"$exportFormat\" format. The report file was not created.")
return
}
renameFile(reportFilePath, modifyReportName(reportFilePath, reportDisplayName))
} finally {
for (GeneratableReport report : availableReports) {
report.release()
}
}
}
// For projects
WsdlProjectReport projectReport = new WsdlProjectReport(project)
exportReport(projectReport, project.name, REPORT_FORMAT, REPORTS_FOLDER)
// For test suites
//WsdlTestSuiteReport testSuiteReport = new WsdlTestSuiteReport(testSuite)
//exportReport(testSuiteReport, testSuite.name, REPORT_FORMAT, REPORTS_FOLDER)
Please note - the REPORTS_FOLDER and REPORT_FORMAT variables must be set to the desired values. If you desire to modify the format of the generated report names, you can do it in the "modifyreportname" method.
If you have many projects/test suites to generate the reports, it is recommended to create folders for separate test runs.
January
February
March
April
May
June
July
August
September
October
November
December
2022
2023
2024
2025
2026
2027
2028
Sun
Mon
Tue
Wed
Thu
Fri
Sat
Today