Forum Discussion

maxivis's avatar
maxivis
Regular Visitor
9 years ago

Error on Conditional Goto

Hi guys, I'm pretty new to Groovy and SoapUI test suite, and I'm getting an error when I try to execute a Conditional Goto. The thing is, I have a couple of REST services which answer a JSON string, and I want to create a TestSuite in which service B gets executed only if service A returns an specific code on its answer. So, to make things more clear:
Service A returns something like:

 

{
    {
        "parentObject": {
            "myCode": "0",
            ....
    }
}

 

 

If code equals to "1" I should run service B, otherwise not. My Conditional Goto is:

contains(text(), "1")

also tried with

contains(., "1")

If I test this condition from the run icon in the Conditional Goto window, it solves correctly the condition, but if I run it from the TestSuite, I get the message "Missing matching condition, moving on" and executes the service B.
There are only a few search results in Google associated to this error, and only in one of them I've found another option with a Groovy script (link):

 

import groovy.json.JsonSlurper
responseContent = testRunner.testCase.getTestStepByName("Service A step").getPropertyValue("response")
slurperresponse = new JsonSlurper().parseText(responseContent)
myCode = slurperresponse.parentObject.myCode
if ('1'.equalsIgnoreCase(myCode.toString())) testRunner.gotoStepByName("Service B Step")
else log.info("Some error")

 

 

 

but it didn't work, meaning that again the service B gets executed, event when it shouldn't).
I would really appreciate if you could give me a hand here, with any of both options, if you know why the Conditional Goto is showing that error or why the Service B gets executed with the Groovy Script.
Thanks in advance

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    JsonSlurper is a good option for parsing and checking the properties of your response, you will see a lot of examples of this e.g.

     

    see the last part of https://www.packtpub.com/books/content/restful-web-service-mocking-and-testing-soapui-raml-and-json-slurper-script-assertion

     

    like this:

    import groovy.json.JsonSlurper
    
    def jsonString = """{
                       "invoice": {
                         "id": "12345",
                         "companyName": "Test Company",
                         "amount": 100.0
                       }
                     }"""
    
    
    def slurper = new JsonSlurper().parseText(jsonString)
    assert slurper.invoice.id=='12345'
    assert slurper.invoice.companyName=='Test Company'
    assert slurper.invoice.amount==100.0

    Could you perhaps post your whole JSON sample and we can get it sorted?

     

    Regards,

    Rupert