vijaykorde
10 years agoNew Contributor
How to get a groovy variable in a REST request?
I have a groovy script that defines multiple varibles, and I want to grab the variables in REST request. How can I do this?
Example:
GS_Example
def var1="1"
def var2="2"
REST_Example
"var1": "${GS_Example#var1}"
"var2": "${GS_Example#var2}"
I do not think this is the correct way to do it? When I right click to add data, I get two options ending with either #result or #script but not for the variables themselves.
- I believe that you will not be able to access the variable that is defined in the groovy script step in other steps. Instead, you need to set the value of the variable to test case property so that can be accessed in any step.
In groovy script step:
context.testCase.setPropertyValue('PROPERTY_NAME', 'PROPERTY_VALUE')
In the request steps that can be accessible by:
${#TestCase#PROPERTY_NAME}