使用Postman验证数据

fzsnzjdm  于 2023-04-06  发布在  Postman
关注(0)|答案(1)|浏览(167)

朋友们,从这种情况下,我采取以下错误响应:

**FAIL检查值为1或2|TypeError:无法读取未定义的属性(阅读“gender”)

FAIL检查值fullName|TypeError:无法读取undefined的属性(阅读'fullName')**

const response = pm.response.json();
    
pm.test("Check value is either 1 or 2", function() {
    pm.expect(response.naturalPerson.gender).to.be.oneOf([1, 2]);
});

pm.test("Check value fullName", function() {
    pm.expect(response.naturalPerson.fullName).to.eql("Bia Teste");
});
{
   "party":{
      "partyId":1555,
      "partyExternalId":"0",
      "partyType":1,
      "partyIdentification":{
         "partyIdentificationType":1,
         "documentNumber":"16250560017"
      },
      "naturalPerson":{
         "fullName":"Bia Teste",
         "gender":2,
         "pronoun":1,
         "maritalStatus":{
            "maritalStatusSituation":2
         },
         "filiation":{
            "fullNameFirstFiliation":"Ana Souza",
            "firstFiliationType":1,
            "fullNameSecondFiliation":"João Souza",
            "secondFiliationType":2
         },

enter image description here

wz8daaqr

wz8daaqr1#

你忘记了JSON路径中的party,下面的代码可以做到这一点:

pm.test("Check value is either 1 or 2", function() {
    pm.expect(response.party.naturalPerson.gender).to.be.oneOf([1, 2]);
});

pm.test("Check value fullName", function() {
    pm.expect(response.party.naturalPerson.fullName).to.eql("Bia Teste");
});

相关问题