How to run SoapUI API commands in an external script
Does anyone know how to run SoapUI commands from an external script?
For example if I have an external script that does an evaluation based on an XML response and if I get the wrong response I want the test to fail how do you add testRunner.fail()
Here is an example of a class I have sitting in my script library. I can call it and pass inputs to it but I can't get it to actually fail the test case.
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") { testRunner.fail('SERVICE IS NOT AVAILABLE') } } }
I have many tests that rely on the "serviceAvailabilityResult" and would rather not have to create a groovy step in each one to do this one thing in case I need to add to it or make changes in the future I would rather have only one place for maintenance purposes.
groovyguy, you shouldn't need to import the entire library.
Reworking the original Class file a bit (I've made the getServiceAvailabilityResult method static for ease of calling, but I understand that this is just a cut down example so this may not be possible with the actual script):
package library.serviceAvailabilityResult class ServiceAvailabilityResult { static String getServiceAvailabilityResult(testRunner, String result) { def serviceAvailabilityResult = '' if(result == "yes") { serviceAvailabilityResult = result }else if(result == "no"){ serviceAvailabilityResult = 'SERVICE IS NOT AVAILABLE' testRunner.fail(serviceAvailabilityResult) }else{ serviceAvailabilityResult = 'Unrecognised input result parameter value "' + result + '"' } return serviceAvailabilityResult } }
I could then call this from a test case setup script, like so:
import library.serviceAvailabilityResult.ServiceAvailabilityResult // The variable inputString must be 'yes' or 'no' def inputString = 'no' def returnString = ServiceAvailabilityResult.getServiceAvailabilityResult(testRunner, inputString) log.info('ServiceAvailabilityResult.getServiceAvailabilityResult = ' + returnString)
with the test case being failed as expected.
jkrier, if your requirement for having an external script was to just have one script to maintain I would still recomend that you investigate Ready APIs Event functionality.