1
votes

I have a groovy script say test.groovy. It has all the instruction to be executed and is stored at a location.

I am creating a SOAP test where I have a groovy step and I want to write in it the code to execute the above script test.groovy.

How can I do this?

1
May be you want to provide some more context and what are you trying to achieve? By the way, what does test.groovy does? - Rao
Groovy is just Java. Your "script" needs to be in a class and a method, and you would call it just like any other method. - SiKing
Possible duplicate of How to run groovy script in java? - Rao
My test.groovy is used to make jdbc connection to my oracle database and perform some sql query.I have externalize this test.groovy as it will be used repeatativly and I want to execute it during my soap test.in my soaptest case I have added a groovy test step where I want to call this script - Vidushi Shukla
You want to try the script from above mentioned link, that should work. You again need to repeatedly the test.groovy from a groovy. And how do you get the result to calling script to evaluate or to make assertions? - Rao

1 Answers

0
votes

Just add the following three lines into the SoapUI Groovy Script.

def project= testRunner.testCase.testSuite.project.workspace.getProjectByName("projectName")
def runner = project.testSuites['testSuiteName'].testCases['testCaseName'].testSteps["groovyScriptName"].run(testRunner, context)
log.info ("runner status ....... : " + runner.getStatus()) // prints the response of the nested script in the log

Change the projectName, testSuiteName, testCaseName, groovyScriptName according to your SoapUI Project. (groovyScriptName is the script which needs to be called)

It just worked on me, and ran a Groovy Script from another groovy script.

Ps: Just in case to verify if the project is being called properly,
add the following code line in between the def project and def runner.

log.info project.name // just to verify the project