Forum Discussion

Cleo-Juniper's avatar
Cleo-Juniper
New Contributor
2 years ago

How do you reuse your ReadyAPI Groovy scripts if you want to run tests in a pipeline?

"Create custom Groovy classes, embed your reusable Groovy scripts into their methods, save them as separate files with the .groovy extension and voila - your Script Library is ready. You just need to point ReadyAPI where to find it (Preferences > ReadyAPI > Script library). If you change anything in those external classes, ReadyAPI will detect this and reload the classes automatically."

 

Does this work if you're running the tests in a pipeline or from a commandline on your local machine?  How would you point your commandline run script to the groovy script library?  And where would you recommend keeping this library if it is being used in multiple projects?  We have multiple projects but kept within the same repo (not using git's integration with readyapi, as this doesn't allow for multiple projects in the same repo).  Ideally what I want is for someone to pull down the tests from git and then just open up readyApi and be able to run the tests.  I don't want them to have to do lots of configuration to be able to run the tests.

  • KarelHusa's avatar
    KarelHusa
    Champion Level 1

    Cleo-Juniper,

    if your external Groovy/Java code needs to be shared amongst all tests, you can place it in a separate Git repo.

     

    At your local computer, checkout the repo and configure your ReadyAPI to point into that directory.

     

    In the pipeline, you need to setup ReadyAPI. Checkout of the shared code repo would be part of this ReadyAPI setup (probably as a ready-made container). So in each test pipeline you won't need to do extra work.

     

  • nmrao's avatar
    nmrao
    Champion Level 3

    Alternatively, create classes / methods in groovy or java instead of script files.

    Compile them and create a jar file and place it under ReadyAPI_HOME/bin/ext directory.