cancel
Showing results for 
Search instead for 
Did you mean: 

SoapUI 5.5.0: conditional perform step using Groovy (previous response has mtom content type)

SOLVED
Highlighted
Occasional Contributor

SoapUI 5.5.0: conditional perform step using Groovy (previous response has mtom content type)

Snippet response teststep: signDocuments:
<soap:Reason>
<soap:Text xml:lang="nl">13 - De transactie is nog niet ondertekend.</soap:Text>
</soap:Reason>
<soap:Detail>
<ns1:Validatiefout xmlns:ns1="https://schemas.knb.nl/css/2.0">
<ns1:code xsi:type="xs:int" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">13</ns1:code>
</ns1:Validatiefout>
</soap:Detail>

Next step: groovy script:

try {
soapResponse = testRunner.testCase.testSteps['signDocuments'].testRequest.response.responseContent;
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
if(soapResponse.contains("soap:Fault") &&
soapResponse.contains("13 - ")) {
sleep(100)
testRunner.gotoStepByName("signDocuments")
}
} catch(Exception e) {

}

 

Goal: perform teststep 'signDocuments' as often as needed until the response doesn't contain message '13'.

I've tried a lot of different ways (including runStepByName, using property transfer, other code using for loop), but still it doesn't seem to iterate over the teststep and groovy script. 
Does anyone have a clue?
 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Occasional Contributor

Re: SoapUI 5.5.0: conditional perform step using Groovy

Hi @HimanshuTayal @richie that worked!
Thanx for helping.

 

So the groovy script now is:

soapResponse = testRunner.testCase.getTestStepByName("signDocuments").getPropertyValue("Response");
//log.info(soapResponse)
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);

if(soapResponse.contains("13 - "))
testRunner.gotoStepByName("signDocuments")

else
testRunner.gotoStepByName("getTransaction")

testRunner.testCase.getTestStepByName("Get status afgerond").getPropertyValue("Response")

View solution in original post

10 REPLIES 10
Highlighted
Community Leader

Re: SoapUI 5.5.0: conditional perform step using Groovy

@robvandehel :

 

You can try like this:

 

try{
	soapResponse = testRunner.testCase.testSteps['signDocuments'].testRequest.response.responseContent;
	def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
	while(soapResponse.contains("soap:Fault") && soapResponse.contains("13 - ") ) 
	{
		runTestStep = testRunner.testCase.getTestStepByName("signDocuments")
		runTestStep.run(testRunner,context)
soapResponse = testRunner.testCase.testSteps['signDocuments'].testRequest.response.responseContent;
	}
}
catch(Exception e){
	log.info "Exception occurs : "+e.toString()
}

 


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Occasional Contributor

Re: SoapUI 5.5.0: conditional perform step using Groovy

Hi @HimanshuTayal,

Thanx for your reply, but that didn't do the trick.
I copied your code in the Groovy script and now get the following error:

  • Tue Jun 16 15:59:14 CEST 2020:INFO:Exception occurs : groovy.lang.MissingPropertyException: No such property: responseContent for class: com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.WsdlMimeMessageResponse Possible solutions: responseContent

I've searched the internet and tried a couple of things, but without any result.

Highlighted
Community Hero

Re: SoapUI 5.5.0: conditional perform step using Groovy

Hey @robvandehel,

Im not a coder like Himanshu is, i just tend to plink away after asking Himanshu and Rao lots of questions, but when im trying to put a bit of code together myself i start with the easiest most simple code i can and build upwards adding complexity once ive got the basics working.

You have a try/catch block in your original code, but i dropped this as what youre trying to do is unlikely to throw an exception.

I also add logging to ensure my variables get defined as expected.

I removed the AND (&&) in your IF. You mentioned in your original post you wanted to re-execute the 'signDocuments' step until '13 -' was no longer generated in the response, so i removed the check for the response containing the 'soap:Fault' string to simplify everything. Obviously if your valid responses include the '13 -' string youll need to alter the IF to ensure what your referencing in the 'contains' is unique to the invalid responses youre checking for.

So the code i updated equates to the following:


soapResponse = testRunner.testCase.testSteps['signDocuments'].testRequest.response.responseContent;
//log.info(soapResponse)
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);

if(soapResponse.contains("13 - "))
testRunner.gotoStepByName("signDocuments")

else
testRunner.gotoStepByName("NextStepAfterThisGroovyStep")


The above might not work (although i cant see why it wouldnt) but it might give you a starting point of the most basic version of your code to try and build upon?

Nice one!

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Occasional Contributor

Re: SoapUI 5.5.0: conditional perform step using Groovy

Hi @richie,

Thanx for your reply. Your code is more simple and seems to work too.
But I still get the same error:
groovy.lang.MissingPropertyException: No such property: responseContent for class: com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.WsdlMimeMessageResponse
Possible solutions: responseContent

The content type of the response is:

Content-Typemultipart/related; type="application/xop+xml"; boundary="uuid:<some UUID>"; start="<root.message@cxf.apache.org>"; start-info="application/soap+xml"

 

I'm starting to think if this has something to do with that. I tested the script in combination with a request which response has content type:

Content-Typeapplication/soap+xml;charset=utf-8

That works just fine.

So I have to figure out how to alter the script so it also understands the multipart (mtom) content type. 

Tags (1)
Highlighted
Community Hero

Re: SoapUI 5.5.0: conditional perform step using Groovy

Hey @robvandehel,

Its never easy! Just to be clear ive exhausted my knowledge on this issue. Normally if i dont like the Content-Type of the response i change it to something i do like using the Accept header on the request. This works fine for simple datatypes but i wouldnt know where to start on a complex multipart type im afraid.

Once/if you do find the answer could you post it please? Its something i may come across in the future so would welcome the education!

Cheers,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Leader

Re: SoapUI 5.5.0: conditional perform step using Groovy

@robvandehel :

 

Could try the below :

testRunner.testCase.getTestStepByName("signDocuments").getPropertyValue("Response")

 


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Occasional Contributor

Re: SoapUI 5.5.0: conditional perform step using Groovy

Hi @HimanshuTayal @richie that worked!
Thanx for helping.

 

So the groovy script now is:

soapResponse = testRunner.testCase.getTestStepByName("signDocuments").getPropertyValue("Response");
//log.info(soapResponse)
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);

if(soapResponse.contains("13 - "))
testRunner.gotoStepByName("signDocuments")

else
testRunner.gotoStepByName("getTransaction")

testRunner.testCase.getTestStepByName("Get status afgerond").getPropertyValue("Response")

View solution in original post

Highlighted
Community Hero

Re: SoapUI 5.5.0: conditional perform step using Groovy

Hey @robvandehel

Great news!

Hey @HimanshuTayal. Is there any chance you can explain (making the explanation as simple as possible) why testRunner.testCase.getTestStepByName("signDocuments").getPropertyValue("Response") works for multipart response but the alternative (that works for basic responses) didnt work in this case? Just wondering as this will assist my groovy education!

Thanks man,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Leader

Re: SoapUI 5.5.0: conditional perform step using Groovy

Sure @richie, the answer is .getPropertyValue("Reponse") fetch the value from the custom properties of that desired step. Refer below screenshot:

HimanshuTayal_0-1592576896229.png

Like wise you can fetch any value using .getPropertyValue("NAME__OF__PROPERTY")

Response

RawResponse

Endpoint

Username

Request

Domain

ResponseAsXml

 

Hope it will help you in understand the logic behind getting the response. 🙂 

 

 

 


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors