Forum Discussion

Mark_E's avatar
Mark_E
Occasional Contributor
15 years ago

Can't load groovy script from script library

Hi,

I am trying to use the script library feature of SoapUI Pro in version 2.5.1 on Windows. I just can't get it to work. When calling a static method on a class or instantiating a class, I receive a "unable to resolve class" error. When I change the groovy file, SoapUI is reporting and update, "MyTest.groovy is new or has changed, reloading...

But using anything in the file fails.

=== MyTest.groovy
package test

public class MyTest
{
  static def test =
  {
      log.info("Hello Test")
  }
}
===
// Groovy script in Groovy Test Step
test.MyTest.test()

Results in: unable to resolve class test.MyTest @ line 1

3 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi!

    is the file in a folder named after its package? (ie "test")

    regards!

    /Ole
    eviware.com
  • Mark_E's avatar
    Mark_E
    Occasional Contributor
    ::) Yes, that works, thanks.

    Is it possible to have a collection of groovy functions/closures in a file without a name space (default package name)?

    So for example have a file called lib.groovy in the scripts directory with something useful like:

    def logInfo = {t -> log.info(t) }
    def myFunc() { "This is my function" }
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Mark,

    script files must be valid classes, not just arbitrary scripts.
    So, you can create groovy class with static methods or closures and use them in your script.
    And of course if you use default package name put your groovy file into bin/scripts folder.

    regards
    Nebojsa
    eviware.com