Forum Discussion

smakkerlak's avatar
smakkerlak
Occasional Contributor
8 years ago

asserting unique ids

I would like to find sort of a "best practice" solution to this problem.

 

I need to have an unique id with all my requests. I have to assert that the response contains the same id.

If i make a small class that generates unique ids, i have an issue using property expansions in assertions, since one id will be sent in the request and another will be generated when i do the assertion.

 

I can do a script assertion but that is fiddly and takes a long time due to the various structures of the responses. I would very much like to avoid property transfers and instead have a simple method to reference the request i just sent as my expected value. Is this possible with a jsonpath match assertion somehow?

  • You can use property expansion to refer to the current request:

    ${Test Step Name#Request#<json path expression>}

    For example, if the request body is

    {"id": "${#TestCase#ID}"}

    the assertion can refer to the request field "id" as:

    ${TestStep Name#Request#$.id}
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    You can use property expansion to refer to the current request:

    ${Test Step Name#Request#<json path expression>}

    For example, if the request body is

    {"id": "${#TestCase#ID}"}

    the assertion can refer to the request field "id" as:

    ${TestStep Name#Request#$.id}
    • smakkerlak's avatar
      smakkerlak
      Occasional Contributor

      Thank you, you have saved me a lot of time. I felt like this should be possible but couldnt find the right information.

       

      Out of curiosity, can i do a self reference in a property expansion? If i can do something like ${#self#request} i won't have trouble if i copy/move/rename my things.

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)
        ${${=context.currentStep.label}#Request#$.id}