Forum Discussion

surya123's avatar
surya123
Occasional Contributor
15 years ago

messageExchange not recognised

def holder = groovyUtils.getXmlHolder( messageExchange.responseContent );

When I try to execute this script , I get this pop up which says groovy.lang.MissingPropertyException:No such property:messageExchange for class: Script35

Please find the screenshot of the pop up attached.

I desperately need this to work ,where am I making a mistake?
  • wdowling's avatar
    wdowling
    Occasional Contributor
    I expect that the MessageExchange context is not available to you in the script. You will have to get the response from the request directly.

    def holder = groovyUtils.getXmlHolder(testRunner.testCase.testSteps["XXXStepName"].testRequest.response.getContentAsXml());

    should work.
  • surya123's avatar
    surya123
    Occasional Contributor
    hi There,

    Thanks a lot for the reply, your code does work, however, I would like to use the messageExchange for the same purpose.

    Below is the code which I use :

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def holder = groovyUtils.getXmlHolder(messageExchange.responseContent)

    I am creating context ,but still i get the same error.Do you know any possible reason for this.I am using soapui pro 3.5
    • chinmaynanda's avatar
      chinmaynanda
      New Member

      Hi There,

       

      I believe, 'messageExchange' is works only in Script Assertion. Your purpose can be solved by context.expand().

       

      Thanks,

      Chinmay

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi!

    exactly where in soapUI are you running this script?

    regards!

    /ole
    eviware.com
  • surya123's avatar
    surya123
    Occasional Contributor
    Hi

    So sorry for the late reply on this.
    I am running this in a test suite, in a groovy step.
  • ryanz's avatar
    ryanz
    Regular Visitor

    The syntax is valid, assuming you are running it in Script Assertion. 

     

    Moreover, please make sure your response is in xml format. Some api may sometimes return both json or xml if you does not specifically specify what you accept.

     

    To make sure your response is accepting an xml, adding an Accept header in your request will help.