【问题标题】:How to validate the attributes which starts with @ in postman JS tests如何在邮递员 JS 测试中验证以 @ 开头的属性
【发布时间】:2019-10-25 15:31:31
【问题描述】:

我需要通过 POSTMAN JS 测试验证以下响应中“@type”属性的值。但是当我尝试编写测试时遇到语法错误(无效或意外令牌)

JS测试线:

var jsonData = JSON.parse(responseBody);
console.log(jsonData.ErrorResponse.Result.Error[0].@type)

回复:

{
    "ErrorResponse": {
        "Result": {
            "Error": [
                {
                    "@type": "ErrorDetail",
                    "StatusCode": "400",                    
                }
            ]
        }
    }
}

【问题讨论】:

    标签: postman postman-testcase


    【解决方案1】:

    您需要使用括号符号["@type"] 来访问该值:

    var jsonData = pm.response.json();
    
    console.log(jsonData.ErrorResponse.Result.Error[0]['@type'])
    

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors

    【讨论】:

      猜你喜欢
      • 2020-11-19
      • 2021-01-27
      • 1970-01-01
      • 1970-01-01
      • 2020-06-19
      • 1970-01-01
      • 2018-01-01
      • 1970-01-01
      • 2021-10-04
      相关资源
      最近更新 更多