How to call a variable from another groovy code?
- 6 years ago
There are two options. The first is to use Properties.
testRunner.testCase.setPropertyValue("VAR_fileName", "Test2 Report.txt")
...
def rootFolder = RootResult + testRunner.testCase.getPropertyValue("VAR_fileName")When you set Properties, the advantage is they are saved permanently into the custom properties of the test case. So if you need to run only step B again, the value will still be there. And when you save your project, you will save the latest values for the properties.
The downside is that you can only set properties with String values. And you should be careful that you don't accidentally use a value from a previous run of the test case if it is no longer valid.
You can retrieve properties for use in your requests, too. Just add a property expansion, like this:
${#TestCase#VAR_fileName}
The other option is to use the context.
context.VAR_fileName = "Test2 Report.txt"
...
def rootFolder = RootResult + context.VAR_fileNameThe context is shared between all the test steps. It can hold any type of data, and it is reset each time you run the test case.
When using the context, you will need to run the test case to pass values between steps. If you run only a single test step, that step is run with a brand new context.
You can use these values in requests too. The property expansion looks simply like this (no need to include the word context):
${VAR_fileName}