Forum Discussion

sp00ky's avatar
sp00ky
Occasional Contributor
8 months ago
Solved

How to use @grab in groovy scripts?

Hi!

 

How can I extend groovy script functionality inside ReadyAPI? ReadyAPI version 3.47.0 with Groovy 3.0.14 installed.

I already added latest Apache ivy dependency manager "ivy-2.5.1.jar" to "C:\Program Files\SmartBear\ReadyAPI-3.47.0\bin\ext", but grab command is not working:

@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='1.1.3')
Wed Jul 05 13:21:28 CEST 2023: ERROR: An error occurred in the script of the Groovy Script test step [Groovy Script]:
Wed Jul 05 13:21:28 CEST 2023: ERROR: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script6.groovy: 1: Unexpected input: '@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='1.1.3')' @ line 1, column 81.
   oovy-wslite', version='1.1.3')

 

Thank you in advance!

sp00ky

5 Replies

    • sp00ky's avatar
      sp00ky
      Occasional Contributor

      nmrao Thank you. It is not solving the original problem loading dependencies dynamically via @Grab, but it works. It also proves that loading jar libs from /bin/ext/ folder is working. I guess the ivy lib needs an additional lib like ant to use @Grab command but I will not investigate further.

       

      • TNeuschwanger's avatar
        TNeuschwanger
        Champion Level 2

        Hello sp00ky ,

         

        @Grab is working for me to dynamically acquire libraries...

         

        If anyone needs reference on how to make it work...

         

        1) Obtain latest ivy version from apache.

        https://dlcdn.apache.org//ant/ivy/2.5.1/apache-ivy-2.5.1-bin.zip

        2) Extract the downloaded zip content to your desired location.

        3) Copy the extracted ivy-2.5.1.jar to your ReadyAPI installation 'lib' folder (not the 'bin\ext' folder).   i.e.:

        **   USE  ** C:\Program Files\SmartBear\ReadyAPI-3.47.0\lib\

        **   NOT  ** C:\Program Files\SmartBear\ReadyAPI-3.47.0\bin\ext\

        4) Restart ReadyAPI

        5) Test with following groovy script test step:

         

        // find the PDF links of the Java specifications
        @Grab(group='org.ccil.cowan.tagsoup', module='tagsoup', version='1.2.1')
        def getHtml() {
            def parser = new XmlParser(new org.ccil.cowan.tagsoup.Parser());
            parser.parse("https://docs.oracle.com/javase/specs/");
        };
        html.body.'**'.a.@href.grep(~/.*\.pdf/).each{ log.info it };
        
        

        6) The run of the script will produce content in Log Output window hopefully.  🙂

         

        Regards,

        Todd

    • sp00ky's avatar
      sp00ky
      Occasional Contributor

      nmrao No change. Groovy says unexpected input before @Grap (see error message)

       

      Wed Jul 05 13:40:44 CEST 2023: ERROR: An error occurred in the script of the Groovy Script test step [Groovy Script]:
      Wed Jul 05 13:40:44 CEST 2023: ERROR: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Script9.groovy: 1: Unexpected input: '@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='1.1.2')' @ line 1, column 81.
         oovy-wslite', version='1.1.2')