How to access CONTEXT object in SAVE/LOAD script in Project Settings
I use below two lines of code to check the active environment. Works perfectly in a groovy test step.
However if I put the same two lines in Project Settings->Save Script it does not work. Complains about null pointer.
Any suggestions on how to solve or why this is?
The message "Objects available by default: log, project" is presented but how do I access CONTEXT object?
def env = context.testCase.testSuite.project.getActiveEnvironment().getName()
log.info("Active Environment: " + env)
I have also tried with "log.info("env = " + project.getActiveEnvironment())" but that one returns "INFO: env = com.eviware.soapui.model.environment.EnvironmentImpl@1becd"
Solved! Go to Solution.
Regarding your last line... "I have also tried with "log.info("env = " + project.getActiveEnvironment())" but that one returns "INFO: env = com.eviware.soapui.model.environment.EnvironmentImpl@1becd".
You've missed getName(). E.g. "log.info("env = " + project.getActiveEnvironment().getName())"
Hi, yea, that helped. Thank you so much.
I will leave the ticket open, hopefully I will get some info about possibilities to get hold on context object.
regarding the missed .getName(), it is strange because when I wrote "project." I get a list of different properties and methods to use, like getActiveEnvironment() and I tried to write "." after that as well but did not get any suggestions in Readyapi so I thought there was nothing.
Where did you find this info if I may ask?
Re Where did you find this info if I may ask? It was in your original question!
I too use the get current environment, but I don't use the save scripts, so have never had the issue you have with finding the context.
The functionality where you type dot to get a list of methods and properties isn't entirely reliable. But you can find all methods and props for SoapUI classes on smartbear's site.
For example, if you google "com.eviware test step", you'll get the following link in the results... https://www.soapui.org/apidocs/5.5.0/com/eviware/soapui/model/testsuite/class-use/TestStep.html
I think eviware was the smartbear pre-cursor, which is why I use com.eviware as a prefix to such a search.
There are couple of ways to find the methods.
1. One of them is to use context help from Groovy Script editor using "." (dot) to see the available methods.
2. Other one to look at the API documentation using below link
3. Another way is to use metaClass and print the methods for any class.
Thanks a lot for helping here, Rao and Chris!
Hi @amirse, could you mark the best reply as a solution here?
In case you have additional questions, I suggest that you start a new thread, this will give you more chances to get your anwers! Thank you.
Community and Education Specialist