Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOAPUI: How to include Groovy script from an external file

Tags:

groovy

soapui

How can I include groovy script from an external file? enter image description here

I was tried to use:

def script = new GroovyScriptEngine('d:/soapui/payment.v2').with { 
    loadScriptByName( 'proxy.groovy' ) 
} 
this.metaClass.mixin script

But I get:

enter image description here

Update

Is there exists some possibility to pack my methods into jar or something like this, and use them from Script TextArea?

like image 311
CAMOBAP Avatar asked Jan 16 '13 11:01

CAMOBAP


1 Answers

The simplest way is to use Groovy Test Step within SOAPUI to run the external script using the GroovyScriptEngine. I use GroovyUtils to find the Project's path so that the entire project can be kept in one place to aid source control, editing etc.

import groovy.lang.Binding
import groovy.util.GroovyScriptEngine

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

// location of script file is relative to SOAPUI project file.
String scriptPath = groovyUtils.projectPath + "/groovy/"

// Create Groovy Script Engine to run the script.
GroovyScriptEngine gse = new GroovyScriptEngine(scriptPath) 

// Load the Groovy Script file 
externalScript = gse.loadScriptByName("Utility.groovy")  

// Create a runtime instance of script
instance = externalScript.newInstance()

// Sanity check 
assert instance!= null

// run the foo method in the external script
instance.foo()
like image 150
Martin Spamer Avatar answered Sep 22 '22 19:09

Martin Spamer