Forum Discussion

robvandehel's avatar
robvandehel
Occasional Contributor
5 years ago

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?
 

 

  • robvandehel's avatar
    robvandehel
    5 years ago

    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")

  • 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()
    }

     

    • robvandehel's avatar
      robvandehel
      Occasional Contributor

      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.

      • richie's avatar
        richie
        Community Hero
        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