Forum Discussion

tom_13's avatar
tom_13
Contributor
15 years ago

Set Global Properties by groovy

Hi all,
I know how get global properties (def user = context.expand( '${user}' ))
But I got a problem when tried to set it!

Help please. How to SET global properties by groovy script?

7 Replies

  • Hi!
      you can use this:

    testRunner.testCase.testSuite.project.setPropertyValue("PropertyName","PropertyValue");

    Hope this might help you.

    Regards,
    depeche
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    The code I posted only works if the property already exists. What depeche posted is correct, but the code works project level properties, not for the global properties. However the change to write global properties is simple:


    com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils.globalProperties.setPropertyValue('PropertyName', 'PropertyValue')


    This will set a global property, and first create it if it doesn't already exist.

    Regards,
    Dain
    eviware.com
    • DeeJunFan's avatar
      DeeJunFan
      New Contributor

      Hi,

       

      I'm pretty new to SoapUI and for me this code isn't creating a global property if it doesnt already exist.

       

      com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils.globalProperties.setPropertyValue('{PropertyName}', '{value})

      Anyone know how i can create Global Properties from a script in a mock service if they dont already exist?

       

      Thanks

      D

      • DeeJunFan's avatar
        DeeJunFan
        New Contributor

        My Apologies,

         

        The code does work.

         

        I had placed the code in the wrong script (had it in the set response)  But the get was being called at an earlier stage which attempted to use the Global property.

         

        So, thanks for the info.  Worked a treat!

         

        D

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    To set a global property, use:



    com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils.globalProperties['user'].value = ...



    replace 'user' with the name of your global property.

    Regards,
    Dain
    eviware.com
  • arunpanjala's avatar
    arunpanjala
    Occasional Contributor
    Hi,

    I'm trying to set global properties and following is the error encountered :

    "java.lang.NullPointerException: Cannot set property 'value' on null object"

    This is the code I'm using to set the global value in start script of my Mock Service : com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils.globalProperties['TestsysUID'].value = "Test";

    Am I missing anything else here? Please suggest.

    Thanks,
    Arun
  • Hi Dain,
          Thats correct dain. What i posted is for project level properties.
    Is there any other way around apart from what i posted to set the project level or test suite level or test case level properties? I mean to say by using com.eviware.soapui.model.propertyexpansion or any other in groovy script.

    Regards,
    depeche