如何处理不同响应的断言 属性 内容?

How to handle assertion property content for differenrt responses?

我想根据以下响应处理断言 属性 内容,无论是成功还是失败。

成功响应:

{
   "task": "userLogin",
   "response":    {
      "code": 0,
      "status": "success",
      "error_message": "",
      "success_message": "",
      "data":       {
         "userId": "65",
         "username": "indian",
         "email": "test@gmail.com",
         "token": "b0aef6139ffdc1041e01f7587a0dcf61",
         "userType": "trial",
         "profile_picture": "test.png"
      }
   }
}

失败响应:将仅缺少 data 个节点,其余节点将存在。

"data":       
    {
        "userId": "65",
        "username": "indian",
        "email": "test@gmail.com",
        "token": "b0aef6139ffdc1041e01f7587a0dcf61",
        "userType": "trial",
        "profile_picture": "test.png"
    }

您可以使用非常简单的 XPath 断言,请记住 SoapUI 在内部将 所有内容 转换为 XML 表示。

XPath:

exists(//*:data)

预计:

true

根据您的意见更新

你原来的要求不明确。该节点存在,它只是空的。在这种情况下,XPath 断言将是:

empty(//*:data)

预计:

false

得心应手XPath reference.