Forum Discussion

sanj's avatar
Super Contributor
6 years ago

Global groovy class or a groovy wrapper class

Let me state what I am curently doing because I have not found a good way of just chaving my code as a class and just re-using it.

Currently I have same grovy code everywhere

How can I just create a class and just import and use it

Issues I have it that the class needs to use Ready API test runners and context in order to run the tests

so that would mean I will have  to import these modules

I have not found a good way of doing ths yet

But in hindsight I would really like to avoid having the same code all over the place.


4 Replies

  • aaronpliu's avatar
    Frequent Contributor

    not sure if you would like to encapsulated your groovy script into a class or method.

    why not you put your groovy code into a .groovy file? ReadyAPI points  to script library(./script) by default, you're able to put your code there. also you can specify a folder to save scripts and then change your script library path setting.

    Surely, defined a class for reference or defined a method to call.


    Login.groovy (you may new a object like: def login = new Login())

    /myTest/Login.groovy (you may new a object like: def login = myTest.Login())

  • Hello sanj


    I was doing the same thing earlier there was no code reusability in my Project but i found below article and this is very usefull for code reusability.

    Please go through this document and follow simple Steps:


    Code Reusability


    Do Like and accept if you find it as solution.




    • Olga_T's avatar
      SmartBear Alumni (Retired)


      Great suggestions, guys! Thank you.


      sanj, have you had a chance to try the suggestions?

      If your question is answered, don't forget to mark this topic as Solved :smileywink:

      Thanks in advance,


      • sanj's avatar
        Super Contributor

        Olga_T Working on the wrapper class to get this resolved.