Forum Discussion

rossird's avatar
rossird
New Contributor
9 years ago

Command Line Update Script Library and Reload

Hello

 

I'm looking for some help or guidance on an issue. My issue has to do with loading the external script library in Ready! API. I want to be able to update the location of the external script library to a location that is relative to the project file (e.g. "$PROJECT_PATH/scripts"), and then be able to make calls on classes in the script library. This also must be possible from a clean install of Ready! API and load of the project file, so I cannot just set it once and then forget it.

So, I've written the following code which accomplishes this task. This code is executed on the project "Load Script" and subsequent calls in the same script on the Script Library work correctly.

 

//Update "Script Library" setting
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projectPath = groovyUtils.projectPath
def isCommandLine = com.eviware.soapui.SoapUI.isCommandLine
log.info "Load Script"
com.eviware.soapui.SoapUI.getSettings().setString("Script Library", "${projectPath}/scripts")
com.eviware.soapui.SoapUI.saveSettings()

 

However, this only work when running from GUI. When running from Command Line OR GUI, I get errors that it cannot find classes present in my external Script Library:

 

"groovy.lang.MissingPropertyException: No such property: mypackge for class: Script1"

"org.codehaus.groovy.control.MultpleCompilationErrorsException: startup failed:

Script1.groovy: 1: unable to resolve class mypackage.myclass ..."

 

For continuous integration testing, I need this to work when invoking "testrunner.bat"/"testrunner.sh" and running tests. I've tried adding the following snippets of code, which do not seem to work either:

 

//Update Groovy Script cache
def engine = new com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory(isCommandLine)
def classLoader = engine.getCoreClassLoader()
def groovyClassLoader = new com.eviware.soapui.support.scripting.groovy.SoapUIGroovyClassLoader(classLoader,   isCommandLine)
groovyClassLoader.syncExternalClasses(true)

and 

 

def core = com.eviware.soapui.SoapUI.getSoapUICore()
core.reloadExternalLibraries()

In the logs, I get messages that it did indeed set the Script Library path correctly and it is resetting the groovy class cache:

INFO  [SoapUIProGroovyScriptEngineFactory] Setting Script Library to [C:\path\to\script\library]

INFO  [SoapUIProGroovyScriptEngineFactory] Resetting groovy class cache due to 78 modified files

 

Any advice on how to get this working from command line as well?

 

EDIT: After further testing, my solution doesn't work even when using the GUI.

EDIT2: Playing around some more and I found that in the GUI, if I move my Script Library calls out of the Project Load Script (where it's updating the Script Library path), it works just fine. However, command line execution still has trouble figuring out the Script Library calls (throws exceptions and such).

No RepliesBe the first to reply