Forum Discussion

PramodYadav's avatar
6 years ago

Get Set and Reset Test case properties from Groovy script

Problem statement: If you are looking for a way to run individual groovy scripts (not full test case) while getting the context variable values set in another script, below may help you.


Note that the solution was already available on forums but parts of solution were scattered in multiple posts. Here I simply consolidate them in one place. Credits are at the end of this post.


Groovy scripts:


//Step1: For this example, Create two properties named zOSUserID and zOSPwd on the test case under which you are going to create below groovy script.


//Step2: Set TestCase parameters value (you can have this in one groovy script on two, depending on what your use case is)["zOSUserID"].value = "fromGroovy"["zOSPwd"].value = "dummy"


//Step3: Get TestCase properties value (again, you may have set the values in one script and may be using it in same or different scripts (mostly this case)


def userID =["zOSUserID"].value //To get Testsuite property, replace testCase with testCase.testSuite "userID : $userID"


def password =["zOSPwd"].value "password : $password"


//Step4: Reset each test case property value (This script, although can be in same script, but will usually be the last groovy script in test case, after which you want to start a new iteration {[it.key].value = '' }

//( above was used for test case. For test suite replace context.testCase with context.testCase.testSuite in the code snippet.)


//To avoid getting script message "end"


Note: You can now run this groovy script and see how the properties are changed at test case level. Comment uncomment the reset part of above code to see how it affects test case parameters. Note that this work for simple variables but not for arrays. If it could work for arrays, that would have been really powerful (for debugging individual scripts at least). For now, even this, can help you where you don't need to pass arrays between scripts. Hope it helps.


Credits and references:

@nmaro :



No RepliesBe the first to reply