0

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",
             "severity": "INFO"
         },
        "message": "operation successfull"
    }

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 (link here) with a Groovy script:

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

UPDATE: the list of steps in the TestSuite, according to @Rao request (sorry, I can't add an image with the real components)

  1. REST service, returning JSON response
  2. Groovy Script, to read a token contained in the previous response and insert it as a header in the next REST service
  3. REST service (this would be "Service A"), returning JSON response (it receives correctly the header inserted in previous step)
  4. Groovy Script (shown in description)
  5. REST service (this would be "Service B"), returning JSON response
    This are my only components in the TestSuite
maxivis
  • 1,727
  • 3
  • 21
  • 35
  • What does `Service A` return? Your example JSON is invalid... – tim_yates Jun 27 '16 at 20:37
  • Hi @tim_yates, is just a fragment of the answer, only to show the variable "myCode" that I'm using, I will update the JSON answer – maxivis Jun 27 '16 at 20:41
  • And what does `log.info(myCode.toString())` show? I suspect it's a list – tim_yates Jun 27 '16 at 21:14
  • @tim_yates When I run the script from the Groovy Script window, it shows the value of the code "Mon Jun 27 18:18:38 ART 2016:INFO: code: 0", I think is not a list – maxivis Jun 27 '16 at 21:19
  • @maxivis, can you please show / list the sequence of steps in the test case? By the way, script looks ok. – Rao Jun 27 '16 at 23:32

1 Answers1

3

It's not possible to use JSON in Conditional Goto in SoapUI. But you can do that with Groovy script.

Here is the snippet found on https://community.smartbear.com/t5/SoapUI-Open-Source/Conditional-goto/td-p/107276

import static com.jayway.jsonpath.JsonPath.parse

def response = context.expand( '${REST Request#Response}' )

def id = parse(response).read('$.id')
log.info id

if (id!=null) testRunner.gotoStepByName("TestStepName")
AnzeR
  • 590
  • 4
  • 11
  • 23