Ask a Question

Loading external groovy script in SOAP UI

check
Not applicable

Loading external groovy script in SOAP UI

Hi,

I have created two groovy script and now I want to use the methods defined in these script in the Start up Script for Test Suite. When I am using the following code:

GroovyScriptEngine gse = new GroovyScriptEngine(groovyUtils.projectPath + "/scripts/")
externalScript = gse.loadScriptByName("utils.groovy")

//GroovyScriptEngine val = new GroovyScriptEngine(groovyUtils.projectPath + "/scripts/")
validationScript = gse.loadScriptByName("Validations.groovy")

context.genAppKeySignInstance = externalScript .newInstance()
context.validationTestInstance = validationScript.newInstance()

assert context.genAppKeySignInstance != null

assert context.validationTestInstanc != null

I am getting the Assertion error for context.validationTestInstance. Can someone please help me why this error is coming?
9 REPLIES 9
SmartBear_Suppo
SmartBear Alumni (Retired)

You didn't share what goes on in your Groovy script and what error is been thrown. But, from the looks of it, "context.validationTestInstanc" in the assert line is missing an 'e'.

Thanks,
Michael Giller
SmartBear Software

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Vidushi
Occasional Contributor

Can you tell me how can i load an external script at test suite level so that i dont have to load it in each test step??

nmrao
Community Hero

What you are trying to achieve in the groovy script which you want to load?


Regards,
Rao.
Radford
Super Contributor

Like mnrao mentioned I'm not sure exactly what you are after.

 

If you are after a central location to store a set of "common library" scripts, you can can specify a Groovy Library directory in the Ready API settings or in the project properties. Any scripts in this library will be accessible from any other scripts within Ready API

 

(Note: I am not sure which value would take precedence if both were set and were different. Personally I only set in the project, as then anyone who opens the project on any Ready API installation will have the correct setting).

 

 

 

 

Vidushi
Occasional Contributor

Actually that external scripts contains all the common function that each test step uses. So rather loading it into each test step i want to load it only once in test suite level.

Radford
Super Contributor

As mentioned above, just put your scripts in a directory (Note: Scripts should be placed in directories named after their containing package)., reference that directory, via the Groovy Library preference and you should be good to go, no need to "load" the scripts at all.

 

Have a read of the above documentation links, in particular the first one.

Vidushi
Occasional Contributor

Thanks for guiding me, I have done as mentioned by using the script as library but it is not able to find methods like this:

public static Map<String,String> getAutoConfigDetails(String fileFullPath)

Any idea??

Radford
Super Contributor

Your script files must be valid classes, not just arbitrary scripts.

 

I usually just create "utility" classes, and make all the methods static when I want simple stand-alone scripts. This documentation page has an example of creating a class with a static method and calling it. Also take note of the section on packages and how that affects the directory structure.

 

The one thing that I do which isn't in that documentation page, is to put import statements in my Groovy scripts that call the library functions, thus for the example on the above page, I would add to my calling script:

 

import readyapi.demo.Callee

 

Vidushi
Occasional Contributor

Thankyou so much for replying. I have one more doubt if  I want to load two groovy scripts ,that are in the same directory, with the same procedure mentioned above then it is not able to load that. Can anyone tell how can i achieve this one?

cancel
Showing results for 
Search instead for 
Did you mean: