Forum Discussion

amirse's avatar
amirse
Contributor
4 years ago

How to access CONTEXT object in SAVE/LOAD script in Project Settings

Hi,

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

    • amirse's avatar
      amirse
      Contributor

      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
        ChrisAdams
        Champion Level 3

        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. 

         

    • sonya_m's avatar
      sonya_m
      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.