【问题标题】:Postman Test getting request body named "email" problem邮递员测试获取名为“电子邮件”的请求正文问题
【发布时间】:2020-10-15 18:01:25
【问题描述】:

我的邮递员请求正文中有这些属性

{    
    "firstName": "QA",
    "lastName": "Test {{agent_phone_number}}",
    "email": "qatest-{{agent_phone_number}}@mail.com"
}

我正在尝试在“测试”选项卡上获取请求正文并将它们设置在集合变量中,代码如下所示

const requestJson = JSON.parse(pm.request.body.raw);

pm.collectionVariables.set('agent_firstName', requestJson.firstName);
pm.collectionVariables.set('agent_lastName', requestJson.lastName);
pm.collectionVariables.set('agent_email'. requestJson.email);

当我运行它时,我得到了这个错误

TypeError: Cannot read property 'email' of undefined

当我检查集合变量时,名字和姓氏被保存,但不是电子邮件..

“电子邮件”是否类似于 Postman 上的“保留”关键字?如果是这样,那么我如何从我的请求正文中获取“电子邮件”属性?

【问题讨论】:

    标签: javascript postman postman-testcase


    【解决方案1】:

    你有一个 .而不是 , 错字:

    pm.collectionVariables.set('agent_email'. requestJson.email);
    

    应该是

    pm.collectionVariables.set('agent_email', requestJson.email);
    

    【讨论】:

      猜你喜欢
      • 2021-10-10
      • 2021-03-04
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 2018-07-12
      • 2011-04-03
      • 1970-01-01
      相关资源
      最近更新 更多