Forum Discussion

bmgriner's avatar
bmgriner
Frequent Contributor
14 years ago

Setting Properties off of groovy assertion script

I am trying to set a test case level property off of a groovy script assertion and I keep getting null pointer errors. I assume the way to do it is as follows:
context.testRunner.testCase.getProperty("someProperty").setValue("somevalue")


Am I doing something wrong here?

3 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    bmgriner wrote:
    I am trying to set a test case level property off of a groovy script assertion and I keep getting null pointer errors. I assume the way to do it is as follows:
    context.testRunner.testCase.getProperty("someProperty").setValue("somevalue")


    Am I doing something wrong here?

    Hello!

    context.testRunner is null in script assertions. Try this instead:

    messageExchange.modelItem.testStep.testCase.setPropertyValue( "My property", "The new value" )

    Regards!

    Good thing you asked this -- I've now added it to the soapUI Tips & Tricks page.

    /Henrik
    eviware.com
    • ilovechiku's avatar
      ilovechiku
      Contributor

       

      Can you use

       

       messageExchange.modelItem.testStep.testCase.setPropertyValue( "My property", "The new value" )

       to get properties back to next request and next assertion of the response? 

       

       

       

       

      • wjblazek's avatar
        wjblazek
        Occasional Contributor

        Script assertions can also access property step properties through the messageExchange object:

        def var = messageExchange.modelItem.testStep.testCase.getTestStepByName("propertyStepName").getPropertyValue("propertyName")
        messageExchange.modelItem.testStep.testCase.getTestStepByName("propertyStepName").setPropertyValue("propertyName", propNameNewValued)

         

        It would be good to add this to the "Tips & Tricks" page too.