2
votes

In SoapUI, I have a host Test Case, which executes another external Test Case (with several test steps) using the "Run Test Case" test step. I need to access a response from the external TC from within my host TC, since I need to assert on some values.

I cannot transfer the properties since they are in XML. Could I get some pointers as to how I could leverage Groovy/SoapUI for this.

3
Can you explain this: "I cannot transfer the properties since they are in XML"? In SoapUI you can transfer anything you want, including entire XML nodes. - SiKing
@SiKing, the external TC has only one property which I could transfer in the 'Run Test Case' test step directly. However, what i need is to transfer the XML response from the external TC into my host TC. - GreenDroid
@SiKing I understand we can transfer XML nodes, and I used that in transferring values in the 'Transfer Property' test step with 'Response as XML' attribute. To rephrase, Could you help me transfer the XML response from a Test Step in an external Test Step into the host TC? - GreenDroid
In you external TC create another property and at the end of the TC use Transfer Property step to transfer your XML node to it. In your host TC, just read that property as you would any other. - SiKing
@SiKing that sounds like a good idea (and would plan on using it), but there are several external test cases which would need to be executed from the host TC. Is there a way to use some Groovy in the host TC to retrieve the response from the external TC? Maybe make use of the context or testRunner variables? - GreenDroid

3 Answers

5
votes

For Response you can use the below code.

testRunner.testCase.getTestStepByName("test step").testRequest.response.responseContent
0
votes

In you external TC create another property and at the end of the TC use Transfer Property step to transfer your XML node to it. In your host TC, just read that property as you would any other.

I also had a look around to see if this can be done from Groovy. SoapUI documentation says that you need to refer to the external name of the testsuite / testcase:

def tc = testRunner.testCase.testSuite.project.testSuites["external TestSuite"].testCases["external TestCase"]
def ts = tc.testSteps["test step"]

But I could not find how to get at the Response after that.

0
votes

In addition to Guest and SiKing answers, I share a solution to a problem that I've met: If your step is not of type 'request' but 'calltestcase' you cannot use Guest answer.

I have a lot of requests contained each in a testCase and my other testCases call these testCases each time I need to launch a request.

I configured my request testCases in order to return the response as a custom property that I call "testResponse" so I can easily access it from my other testCases.

I met a problem in the following configuration : I have a "calltestcase" step that gives me a request result. Further in the test I have a groovy script that needs to call this step and get the response value

If I use this solution :

testRunner.runTestStepByName("test step")

followed by testRunner.testCase.getTestStepByName("test step").testRequest.response.responseContent

I'm stuck as there is no testRequest property for the class.

The solution that works is :

testRunner.runTestStepByName("test step")
def response_value = context.expand( '${test step#testResponse#$[\'value\']}' )

another solution is :

    testRunner.runTestStepByName("test step")
    tStep = testRunner.testCase.getTestStepByName("test step")
    response = tStep.getPropertyValue("testResponse")

Then I extract the relevant value from 'response' (in my case, it is a json that I have to parse).

Of course it works only because I the request response as a custom property of my request test case.

I hope I was clear enough