使用JSR223断言验证JMeter中的请求数据中的必填字段

时间:2018-03-06 11:29:01

标签: jmeter assertion jsr223

我想检查Request Data JSON中是否提供了必填字段。其次要检查是否没有为CustomerType提供支持JSON对象。

这是我要验证的JSON。

{
      "Transaction": {
        "TrType": "Vehicle",  -- This is mandatory field
        "CustomerType": "Individual",  -- This is mandatory field and depend upon Customer type user must have to pass IndividualClient or CompanyClient
      },

      "IndividualClient": {
        "FirstName": "Test First Name",  -- Optional field
        "LName": "Test Last Name",  -- Mandatory field
      },

      "CompanyClient": {
        "CompanyName": "Company Name", -- mandatory field
        }
}

如何通过使用JSR223 Assertion来实现这一目标?

1 个答案:

答案 0 :(得分:0)

您需要根据个人或公司声明

if (jsonRequest.Transaction.CustomerType.contains("Individual")) {
    assert jsonRequest.IndividualClient
    assert jsonRequest.IndividualClient.size() >=0
    assert jsonRequest.IndividualClient.LName
} else {
    assert jsonRequest.CompanyClient
    assert jsonRequest.CompanyClient.size() >=0 
    assert jsonRequest.CompanyClient.CompanyName
}