Forum Discussion

DW's avatar
DW
Occasional Contributor
10 years ago

Setting parameter in REST post xml mesage and checking result

Another noob question...

 

We have a REST xml service that uses Post. It only has one value in the request, lets call it CustomerReference and returns a few details, such as name and if they are active

 

<GetCustRef ns: xxxx>

<message header ns: xxxx>

some stuff

</message header>

<request>

CustomerReference

</request>

</GetCustRef>

 

What I need to do is set the CustomerReference as a parameter in the post message and then check some of the results. I've already found a script that will allow me to loop through different references but nothing that can help with settign the parameter and checking the results.

 

  • Hi,

     

    Assuming you set your customerReference as a property somewhere convenient, propbably on the context variable e.g. context["customerReference"]="12345 (you could set this in a Groovy TestStep preceeding your request for example)

     

    Then its as easy as inserting a property expansion into the request body e.g.

     

    <GetCustRef ns: xxxx>

    <message header ns: xxxx>

    some stuff

    </message header>

    <request>

    ${customerReference}

    </request>

    </GetCustRef>

     

    In terms of checking the results do you need any help with Assertions e.g. content, XPath or Script Assertions are obvious candidates to check XML response values? Note - you could also use property expansions in the Assertions if you have values that you wish to check for that are in properties...

     

    Let me know if this fixes you up or you need any more help.

    Cheers,

    Rup

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    Assuming you set your customerReference as a property somewhere convenient, propbably on the context variable e.g. context["customerReference"]="12345 (you could set this in a Groovy TestStep preceeding your request for example)

     

    Then its as easy as inserting a property expansion into the request body e.g.

     

    <GetCustRef ns: xxxx>

    <message header ns: xxxx>

    some stuff

    </message header>

    <request>

    ${customerReference}

    </request>

    </GetCustRef>

     

    In terms of checking the results do you need any help with Assertions e.g. content, XPath or Script Assertions are obvious candidates to check XML response values? Note - you could also use property expansions in the Assertions if you have values that you wish to check for that are in properties...

     

    Let me know if this fixes you up or you need any more help.

    Cheers,

    Rup

    • DW's avatar
      DW
      Occasional Contributor

      Thanks Rupert, will give that a go. It sounds like what I was after at least

       

      In terms of checking the results, I was thinking it would be some kind of xpath? I currently have the data stored in a txt file as below so whatever option is easiest to check I guess

       

      customerReference, name, active

      12345, Bobs bits, Y

      34567,Handy harry, N

      • rupert_anderson's avatar
        rupert_anderson
        Valued Contributor

        Ok, no problem. 

         

        Assuming your service responds with XML, an XPath assertion is definately a good option (although I personally find XPath expressions awkward to work out!), a Contains Assertion would work too (but only checks for the content, whereas XPath is actually also checking exactly where the content is in the document) and Script Assertions are great as you can then use Groovy e.g. XML Slurper to check the response over.

         

        When using any of the Assertions, remember that (assuming you have name and active read from your CSV file into properties) you can use these properties in the Expected Value / Content / Script with that same property expansion syntax e.g. ${name} and ${active}

         

        That way your test case might look like:

         

        1. Read line of CSV into properties (store on context)

        2. Call service using properties from context as part of request body

        2a. Have Assertions to use ${name} and ${active} to check the response data matches CSV expected data

        3. Loop to next line of CSV or finish

         

        Cheers,

        Rupert