Forum Discussion

joanna's avatar
joanna
New Contributor
6 years ago
Solved

How to assert for a "not null" response in the json response from soap api?

How to assert for a "not null" response in the json response from soap api using groovy scripting

  • You can try something like this snippet of code, that asserts that the repsonse is not null, is not an empty collection, and is not an empty string:

     

    def response = context.expand( '${TestStepName#Response}' )
    assert (response != null) && (response != "") && (response != []);
    

2 Replies

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    You can try something like this snippet of code, that asserts that the repsonse is not null, is not an empty collection, and is not an empty string:

     

    def response = context.expand( '${TestStepName#Response}' )
    assert (response != null) && (response != "") && (response != []);
    
  • You can do this in script assertion by writing below code:

     

    def response = messageExchange.getResponseContent()
    assert (response != null) && (response != "") && (response != []):"Assertion failed, Got Null Response"