Forum Discussion

amirse's avatar
3 years ago

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()"Active Environment: " + env)



I have also tried with ""env = " + project.getActiveEnvironment())" but that one returns "INFO: env = com.eviware.soapui.model.environment.EnvironmentImpl@1becd"

5 Replies

    • amirse's avatar

      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?


      • ChrisAdams's avatar
        Champion Level 2

        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...


        I think eviware was the smartbear pre-cursor, which is why I use com.eviware as a prefix to such a search. 


    • sonya_m's avatar
      SmartBear Alumni (Retired)

      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.