To create your first SOAP test, check here.
SOAP UI pro has direct options to generate reports from the tool itself. But SOAP UI free version doesn't have such options, but we can generate reports using groovy script and external plugins.
Here I am going to show how to create HTML reports using ANT plugin and CSV reports using Groovy scripting.
Generating HTML reports using ANT plugin:
Step 1: Install Ant plugin
You can either directly download Ant from its site. Or if you have eclipse installed in your system, you will find Ant plugin already downloaded in the path "path\eclipse\plugin"
Copy the path of ANT plugin to set system variable
Go to Control Panel -> Edit System variables -> under system Variables create a new path "ANT_HOME" and paste the path of ANT plugin
Click on "Path" from system variable and add "%ANT_HOME%/bin".
You can now open command prompt and type "ant -version" to confirm that your Ant is installed successfully.
Step 2: Save your SOAP project as xml file
Go to SOAP UI, right click on the project you want to create report
Click save as, and save the project as xml file in any location you want.
Step 3: Run SOAP UI project using TestRunner.bat
Go to the folder your soap ui is installed, Open bin to find "TestRunner.bat" file
Copy the path of the folder, go command prompt and set the path as "cd yourPath"
Once the path is set, enter following commands to run your project from command prompt
//to run your project
testrunner.bat "path of the project in xml"
//to run a particular suite from your project
testrunner.bat -s<<SuiteName>> "path of the project in xml"
//to run a particular suite from your project
testrunner.bat -r "path of the project in xml"
And hit enter, to see your test suite is executed from command prompt.
Step 4: Create Build.xml file
Open a notepad and enter the following xml code and save it as "Build.xml" in the same folder you have your project saved.
<project basedir="." default="testreport" name="CodersCamp_TestReportGeneration">
<property name="test.suite" value="TestSuiteName"/>
<property name="soapui.project" value="C:/Users/Username/path/SoapProject.xml"/>
<property name="soapui.home" value="C:/Program Files/SmartBear/SoapUI-5.5.0"/>
<property name="results.dir" value="C:/Users/UserName/Desktop"/>
<property name="reports.dir" value="${results.dir}/Reports"/>
<property name="html.dir" value="${reports.dir}/html"/>
<target name="execute.project">
<exec dir="${soapui.home}/bin" executable="testrunner.bat">
<arg line="-r -s ${test.suite} -f ${results.dir} ${soapui.project}" />
</exec>
</target>
<target name="testreport" depends="execute.project">
<mkdir dir="${reports.dir}"/>
<junitreport todir="${reports.dir}">
<fileset dir="${results.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${html.dir}" />
</junitreport>
</target>
</project>
Here, Specify testSuiteName, Soapui home, Soap project, result directory, report directory, html directory according to your project details in property tag.
Step 5: Run Build.xml to generate report.
Now open your command prompt, set the path where your build file is saved
Enter the command "ant" and hit enter.
You can see you build file is picked and executed, and reports are generated in the path specified in build file.
Generating CSV reports using groovy script:
CSV reports can be generated using groovy scripting. You can customize all the data that needs to be saved in your report in your groovy code.
Let us see a sample code, that generate a csv file and save basic details of the test executed. You can also customize this code according to your requirements.
Step 1: Create a new test suite and test case, create a new groovy test step in that test case.
Step 2: Copy paste the following code in your groovy step.
try {
String folderPath = "C:/Users/UserName/Desktop" + "/SoapUIResults";
def resultFolder = new File(folderPath);
if(!resultFolder.exists())
{
resultFolder.mkdirs();
}
Date d = new Date();
def executionDate = d.format("dd-MMM-yyyy HH_mm");
String subfolderPath1 = folderPath+ "/Request-Response_"+executionDate;
new File(subfolderPath1).mkdirs();
String subfolderPath2 = folderPath+ "/CSV Reports";
new File(subfolderPath2).mkdirs();
def reportFile = new File(subfolderPath2, "Report_"+executionDate+".csv");
if(!reportFile.exists())
{
reportFile.createNewFile();
reportFile.write('"Test_Suite","Test_Case","Test_Step","Step1_Type","Status",'
+'"Result message","Execution_Date"');
}
for(stepResult in testRunner.getResults())
{
def testSuite = testRunner.testCase.testSuite.name;
def testCase = testRunner.testCase.name;
def testStep = stepResult.getTestStep();
def testStepName = testStep.name
def type = testStep.config.type
def status = stepResult.getStatus()
reportFile.append('\n');
reportFile.append('"' + testSuite + '",');
reportFile.append('"' + testCase + '",');
reportFile.append('"' + testStepName + '",');
reportFile.append('"' + type + '",');
reportFile.append('"' + status + '",');
reportFile.append('"');
for(resMessage in stepResult.getMessages())
{
reportFile.append('Message:' + resMessage + '\n');
}
reportFile.append('",');
reportFile.append('"' + executionDate + '",');
if((type=="request").or(type=="restrequest"))
{
def extRequest = testStep.properties["Request"].value;
def requestFile=subfolderPath1+"/request_"+testSuite+"_"+testCase+"_"+testStepName+".txt";
def rqfile = new File(requestFile);
rqfile.write(extRequest, "UTF-8");
def extResponse = stepResult.getResponseContent();
def responseFile=subfolderPath1+"/response_"+testSuite+"_"+testCase+"_"+testStepName+".txt";
def rsfile = new File(responseFile);
rsfile.write(extResponse, "UTF-8");
}
}
}
catch(exc)
{
log.error("Exception happened: " + exc.toString());
}
Step 3: Mention the following code in tear down section of Project or Test Suite to run the groovy script and generate report.
testRunner.testCase.testSuite.project.testSuites["TestSuiteName"].testCases["TestCaseName"].
testSteps["GroovyStepName"].run(testRunner, context);
Now execute the project to see reports generated in specified path.
Thus we have learnt to generate HTML and CSV reports in SOAP UI free version. Happy Testing!!!
Reports are not getting generated. Added the tear down script in one of the suites but the CSV didnt populated.
Hi @Aloïs Dreyfus Have you created the folders as mentioned? To get more idea on the error, can you please attach any screenshots or more details on your suite. Thanks!
I have an error with step 3 of "Generating CSV reports using groovy script" : "MissingPropertyException: No such property: testRunner for class: Script1" :'(