Sharing custom class object between Groovy scripts
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 that creates the object with certain parameters, and then that object would become available to all other Groovy scripts by some ReadyAPI access call, similar to how primitive properties are shared.
Thank you,
-Mdar
Solved! Go to Solution.
- Labels:
-
Function Tests
-
Scripting
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello @Mdar
This sounds like good use of context variable.
Not to re-invent the answer wheel... There will be a lot of information gained from googling:
"context variable readyapi"
Some answer will have touched on your question.
Regards,
Todd
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Todd,
Thank you for the response, I will take your advice to review that thread and context variables.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ili,
Thank you for the response. I gave it a try and it seemed to work fine! It's a bit of an odd pattern I guess to have sort of a "utility script" called by other scripts -- also keeping it disabled because I don't want to run it on it's own.
-Mdar
