Vikram Vikram - 17 days ago 9x
Java Question

Display SOAPUI TestRunner Response in Java

I am using SOAP UI API from Java. I have created my SOAP Project and added a Test Suite and Required Test Cases and Test Steps. I am just wondering is there any way getting the response of test in XML format? Because I want to use this data further in my tests

import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.model.iface.MessageExchange;
import com.eviware.soapui.model.testsuite.TestCase;
import com.eviware.soapui.model.testsuite.TestRunner;
import com.eviware.soapui.model.testsuite.TestSuite;
import org.junit.Assert;
import java.util.List;
public class SoapUITest
public final static void main(String [] args) throws Exception {

WsdlProject project = new WsdlProject("C:\\WebService\\WebServiceTest\\src\\main\\java\\weather.xml");
List<TestSuite> testSuites = project.getTestSuiteList();
for (TestSuite testSuite: testSuites)
System.out.println("Running Test Suite: "+ testSuite.getName());
List<TestCase> testCases = testSuite.getTestCaseList();
for(TestCase testCase:testCases)
System.out.println("Running Test Case: " + testCase.getName());
TestRunner testRunner = PropertiesMap(), false);

//Exception in the below line
System.out.print("Testing finished successfully");

I have added this code
But for obvious reason I am getting the below Exception. Not sure whether I am using the right method.

Exception in thread "main" java.lang.ClassCastException: com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner cannot be cast to com.eviware.soapui.model.iface.MessageExchange
at VMSSoapUI.main(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at com.intellij.rt.execution.application.AppMain.main(

Did some one already implemented this way of sending the request and getting the response in XML format from SOAPUITestRunner? Appreciate your help.

Rao Rao

Below runStepAndGetResponseContent method will run the test step and get the response as string for wsdl request test step type, which I believe, is the one you looking for. And you may add conditions for other instances of test step types as needed.

public String runStepAndGetResponseContent(WsdlTestCaseRunner runner, TestStep testStep) {
        TestStepResult result = runner.runTestStep(testStep);
        if (result instanceof WsdlTestRequestStepResult) {
            return ((WsdlTestRequestStepResult) result).getResponse().getContentAsString();
        return null;

Along with the above new method, below line of code of yours needs to be replaced with below code:

TestRunner testRunner = PropertiesMap(), false);

Replace with: this will loop thru the test steps of a test case.

WsdlTestCaseRunner runner = new WsdlTestCaseRunner((WsdlTestCase) testCase, new StringToObjectMap(testCase.getProperties()) );
for(TestStep testStep: testSteps){
      //calling the above get method here
      String response = runStepAndGetResponseContent(runner, testStep);
      System.out.print("Received response is :" + response);