Forum Discussion

jkrier's avatar
jkrier
Regular Contributor
7 years ago

Running SoapUI specific methods from an external script

I have an external groovy script that evaluates a response ( "yes" or "no" ). If the response is "no" I want the testRunner to fail. This is the code I have in my code library

 

package library.serviceAvailabilityResult

import org.apache.commons.lang.RandomStringUtils

class ServiceAvailabilityResult {

String getServiceAvailabilityResult(String result) {

String serviceAvailabilityResult

if (result == "yes") {
serviceAvailabilityResult = result
} else if (result == "no") {
return testRunner.fail('SERVICE IS NOT AVAILABLE')
}
}
}

This obviously fails. Does anyone know how to return the 

 

testRunner.fail('SERVICE IS NOT AVAILABLE')

 

in a way that SoapUI sees it as a command? 

 

I am calling the method above in a groovy script that looks like this

 

def myServiceAvailabilityResult = new ServiceAvailabilityResult()
String result = "no"
String myResult = myServiceAvailabilityResult.getServiceAvailabilityResult(result)
log.info myResult

12 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    The method return type is String. However, in the else part below would return void / nothing.

    testRunner.fail

     

    I believe that it can be more simplified if you can specify more details like what response and what is the expected result.

    • jkrier's avatar
      jkrier
      Regular Contributor

      Well if the response is "no" I would like to return the SoapUI command "testRunner.fail()" and have the test fail. Am I not explaining that correctly?

       

      I would like for the test to fail at that point just like I would if I was running this in a Groovy step in the project itself.

       

      • nmrao's avatar
        nmrao
        Champion Level 3
        Well, test can be failed, But nothing to return.