【问题标题】:How to compare a input value to value in results如何将输入值与结果中的值进行比较
【发布时间】:2020-06-09 08:18:14
【问题描述】:

这是我的意见

{
  "AccountId": "9834e8cb-275a-4bff-b362-f216e9653686",
  "ContactId": "9834e8cb-275a-4bff-b362-f216e9653686",
  "AuthenticationDetails": {
    "AuthenticationId": "{{clientId}}",
    "AuthenticationType": "Token"
  }
}

这是我的输出

{
    "orderedByContactId": "36b8e4da-94fd-4680-a2d3-6b128e4b2584",
    "orderedForContactId": "9834e8cb-275a-4bff-b362-f216e9653686"
}

我需要创建一个测试(邮递员)以确保输出值(“orderedForContactId”)与输入值(“ContactId”)匹配。有人可以帮帮我吗?

现有的测试格式如下:

pm.test("Response should contain orderedForContactId",function(){
    let jsonRespData = pm.response.json();

    pm.expect(jsonRespData).to.have.property('orderedForContactId');
});

【问题讨论】:

  • 执行现有测试时遇到什么错误?
  • 我没有收到错误,我只是不确定如何在测试中确保输入值与输出值匹配。 (我在问题中包含的测试示例正在运行并返回阳性测试结果)。
  • 我要做的是创建一个测试,其中“Input-ContactId{value}”=“Output-orderedForContactId{value}”,但不知道如何获取要使用的值他们。

标签: testing automation postman


【解决方案1】:

我把输入改成

{
  "AccountId": "9834e8cb-275a-4bff-b362-f216e9653686",
  "ContactId": "{{ContactId}}",
  "AuthenticationDetails": {
    "AuthenticationId": "{{clientId}}",
    "AuthenticationType": "Token"
  }
}

并将 ContactId 添加到环境文件中。 然后我创建了下面的测试:

pm.test("Input ContactId should equal orderedForContactId",function(){
    let jsonRespData = pm.response.json().orderedForContactId;
    pm.expect(jsonRespData).to.equal(pm.environment.get("ContactId"))
});

【讨论】:

    【解决方案2】:

    将此作为您的测试脚本

    pm.test("Response should contain orderedForContactId",function(){
       var requestJson= JSON.parse(pm.request.body.raw);
       var contactId = requestJson.ContactId.toString();
       var responseJson = pm.response.json();
       var orderedForContactId = responseJson.orderedForContactId;
       pm.expect(orderedForContactId ).to.equal(contactId);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-16
      相关资源
      最近更新 更多