Forum Discussion

Mdar's avatar
Mdar
Occasional Contributor
2 years ago
Solved

Sharing custom class object between Groovy scripts

Hello,   I was wondering if it was possible to create a Java object (from an imported package) and save it to some ReadyAPI global scope storage feature. So I would have an initialization script th...
  • ili's avatar
    2 years ago

    Hi Mdar if I understood correctly your requirement I believe groovy's MetaClass Programming feature to store an object for sharing could be of help.

    Basically each Class can have metaclass in background that defines behaviour of the same class. Objects can be defined and shared.

    ReadyAPI example:

    - save the object:

    testRunner.metaClass.savedObject = objectToShare

    - then if I want to get the same object say for example from a test step (groovy script):
    def myObject = testRunner.savedObject