0

API Response

[Data:[DuplicateInvoiceReference:null, RequestID:null], Error:[[Code:API.INV.005, Description:Invoice Reference is null or empty]], 
Status:3, Warning:null]

I'm going to asset the Error Object, below is my code

def responseData = jsonSlurper.parseText(responseBody)
assert responseData.Error.Description == "Invoice Reference is null or empty"

but I received assertion failed

assert responseData.Error.Description == "Invoice Reference is null or empty"
       |            |     |           |
       |            |     |           false
       |            |     [Invoice Reference is null or empty]
       |            [[Code:API.INV.005, Description:Invoice Reference is null or empty]]
       [Data:[DuplicateInvoiceReference:null, RequestID:null], Error:[[Code:API.INV.005, Description:Invoice Reference is null or empty]], Status:3, Warning:null]

Please clarify the issues in the assertion part?

1
  • Please include the output of responseData.Error.Description.class. Commented Aug 25, 2020 at 7:22

1 Answer 1

2

You're reading Description as though Error were a map. It is a list.

You should be having

assert responseData.Error[0].Description == "Invoice Reference is null or empty"

You need to read Description off the first element of responseData.Error

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.