Report Generation in SoapUI using Extent Report
HTML Report Generation in SoapUI using Extent Report
Objective - Today we will see how to overcome the SoapUI limitation of report generation. This option is available in the SoapUI Pro (ReadyAPI) tool but unfortunaely note available in free version. We will use the inbuilt Groovy script option coupled with the Extent Report jar to overcome this limitation. This script has been placed in the Teardown Script Section at the Project Level. The Extent Report jars and TestNG jars need to be placed inside the SOAPUI_INSTALLATION_PATH\bin\ext and can be downloaded from their official site - Extent Report Official Site and TestNG Official respectively.
Stratergy Used
- Based on the various assertion we have implanted in the various test step, the assertion result and report output can be categorized in 3 parts
- Assertion Status - SUCCESS, Report - Pass
- Assertion Status - FAIL, Report - Fail
- Assertion Status - UNKNOWN, Report - Warning
- In Extent Report, there are 4 types of Strategy - TEST (default), CLASS, SUITE, BDD. We have opted for SUITE as it gives 3 tier view making it perfect for SoapUI hierarchy - Test Suite -> Test Case -> Test Step
Note: The warning status in report helps us to understand that some assertions have been disabled.
Outcome - A beautiful HTML report
/*
@Author - Sumeet Agrawal
@Email Id - sumeetagrawal840@gmail.com
*/
//Importing all necessary packages
import com.eviware.soapui.model.testsuite.*;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.*;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import com.aventstack.extentreports.reporter.configuration.Theme;
import com.aventstack.extentreports.AnalysisStrategy;
import java.text.*;
//Get current timestamp
SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd HH-mm-ss');
def currentDateString = sdf.format(new Date())
//Creating necessary objects of Extent Reported
ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest logger;
ExtentSparkReporter spark;
/*
Defining output folder.
Kindly note context.expand('${projectDir}') will give the current Project output file directory as output.
*/
def outputFolder = context.expand('${projectDir}')+File.separator+'Reports_'+currentDateString
spark = new ExtentSparkReporter(outputFolder);
htmlReporter = new ExtentHtmlReporter(outputFolder+File.separator+"Report_"+currentDateString +".html");
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
extent.attachReporter(spark);
extent.setAnalysisStrategy(AnalysisStrategy.SUITE)
extent.setSystemInfo("User Name", "Sumeet Agrawal");
projectName = runner.project.name
htmlReporter.config().setDocumentTitle("Report - "+ projectName + currentDateString );
htmlReporter.config().setReportName(projectName +' - ' + currentDateString );
htmlReporter.config().setTheme(Theme.STANDARD);
htmlReporter.config().setTimeStampFormat("yyyy-MM-dd HH:mm:ss")
//Looping through all the test suites. Kindly note the test suites that are disables will not be considered.
runner.project.testSuiteList.each{
testSuite ->
if(!testSuite.isDisabled()){
testsuite_logger = extent.createTest(testSuite.getName());
//Looping throught all test enabled test cases for all test suites
testSuite.testCaseList.each{
testCase->
if(!testCase.isDisabled()){
testcase_logger = testsuite_logger.createNode(testCase.getName());
testCase.testStepList.each{
//Looping through all test steps that are assertable
testStep ->
if( testStep instanceof Assertable && (!testStep.isDisabled())){
assertionStatus = []
testStep.getAssertionList().each{
assertion ->
assertionStatus.add(assertion.getStatus().toString()+" - "+assertion.getLabel())
}
logger = testcase_logger.createNode(testStep.getName());
assertionStatus.each{
if(it.startsWith("VALID -")){
logger.log(Status.PASS, MarkupHelper.createLabel(it, ExtentColor.GREEN));
} else if(it.startsWith("FAILED -")){
logger.log(Status.FAIL, MarkupHelper.createLabel(it, ExtentColor.RED));
} else {
logger.log(Status.INFO, MarkupHelper.createLabel(it, ExtentColor.BLUE));
}
}
testcase_logger.assignCategory(testSuite.name + ' - '+testCase.getName())
}
}
}
}
}
}
//Generating Output
extent.flush();
I can't find jar files on the official Extent Report website.
ReplyDeletePlease help me.
You can also visit maven repository and download from there https://mvnrepository.com/artifact/com.aventstack/extentreports/4.0.9
ReplyDeleteThank you very much for your help.
Deletehi when i try this in my soap ui which is a mac version 5.50
ReplyDeletei added some debugging steps and it fails on this line
spark = new ExtentSparkReporter(outputFolder);
htmlReporter = new ExtentHtmlReporter(outputFolder+File.separator+"Report_"+currentDateString +".html");
ive tried to wrap that line in a try catch block but the catch block is not executing any code inside it so i dont know what exception is throwing can you please help ?
Hi ... same above problem i am also facing so any help regarding the issue
ReplyDeleteCheck this https://github.com/iamakshayshar/SoapUI-Extentter
DeleteYou don’t need this all scrips
ReplyDeleteOr jar files. Here’s the plug and play utility which can generate extent report for you. https://github.com/iamakshayshar/SoapUI-Extentter