Forum Discussion

jkrier's avatar
jkrier
Regular Contributor
7 years ago
Solved

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 wa...
  • Radford's avatar
    Radford
    7 years ago

    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.