【问题标题】:How can we verify response data schema(column values only) in jmeter?我们如何在 jmeter 中验证响应数据模式(仅限列值)?
【发布时间】:2017-03-09 10:14:58
【问题描述】:

我需要在 jmeter 中验证 API 架构。 我的 API 响应数据是

[{
    "snid": "1",
    "subject": "Automation",
    "state": null,
    "country": null,
    "contact_name": "John",
    "email": "John@gmail.com",
    "phone": "402-221-9999"
}, {
    "snid": "2",
    "subject": "Testing",
    "state": null,
    "country": null,
    "contact_name": "Smith",
    "email": "jmstauch@leoadaly.com",
    "phone": "402-111-2222"
}]

所以我想验证它是否包含响应消息

{
    "snid": "",
    "subject": "",
    "state": ,
    "country": ,
    "contact_name": "",
    "email": "",
    "phone": ""
}

我只需要验证字段的列名和顺序。 我使用了response assertions contains 但它不验证订单,JSON path assertion 验证对象值而不是参数(或验证完整消息),但在我的情况下,我需要验证确切的架构。

请帮忙

【问题讨论】:

    标签: api jmeter assertion


    【解决方案1】:

    您可以使用map.keySet(),它会为您提供地图中的所有键。

    [ "snid",
      "subject",
      "state",
      "country",
      "contact_name",
      "email",
      "phone"
    ]
    

    【讨论】:

      【解决方案2】:

      我建议使用JSR223 AssertionGroovy JSON Schema,因为目前没有相关的捆绑测试元素和/或插件来涵盖此功能。确保你有JMeter Classpath中的.jar

      有关在 JMeter 中使用 Groovy 脚本的更多信息,请参阅 Groovy Is the New Black 文章。

      【讨论】:

        【解决方案3】:

        我找到了解决方法 首先将对象解析为 json slurper

        def slurper = new groovy.json.JsonSlurper();
        
        def response = slurper.parseText(prev.getResponseDataAsString());
        
        def testdata = response[0].keySet() as List;
        

        这会将测试数据保存为

        [ "snid","subject","state","country","contact_name","email","phone"]

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-02-03
          • 1970-01-01
          • 1970-01-01
          • 2011-04-30
          • 1970-01-01
          相关资源
          最近更新 更多