Forum Discussion

Vivi's avatar
Vivi
Occasional Contributor
7 years ago

Assertion returns null when json node has value

Hi everyone! I am trying to get and assert the vale of the node first from the following json response but the assertion returns null even when the value is returned : {"registers":{           ...
  • Vivi's avatar
    Vivi
    7 years ago

    Hi!

     

    Thank you for answering so fast! But what I posted was not the real response but only a mock so that I could explain what the problem was (As I cannot publish online the real response) so that didn't work for me.

     

    Today I tried something else and it worked. Here is I used in my script:

    import groovy.json.JsonSlurper
    def response=messageExchange.response.responseContent
    def json=new JsonSlurper().parseText(response)

    if (json.registers.name){

    def first=context.expand('${testStepName#Response#$[\'registers\'][\'name\'][\'first\']}')

    assert first!=null

    }

     

    I can't figure out why the first script didn't work and returned null but this solution is working for me and I get the right value from the response.