Forum Discussion

check's avatar
11 years ago

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?
  • Radford's avatar
    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).

     

     

     

     

  • SmartBear_Suppo's avatar
    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
  • Vidushi's avatar
    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's avatar
    nmrao
    Champion Level 3
    What you are trying to achieve in the groovy script which you want to load?
    • Vidushi's avatar
      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's avatar
        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.