如何使用csv文件在jmeter中传递json对象?

时间:2018-06-08 10:42:59

标签: jmeter

这是json对象

{  
   "addLabourerToSpecificShift":false,
   "isEarlySubmit":true,
   "isExistinglabourer":false,
   "task":"add",
   "currentDate":"2018-06-08T07:08:21.296Z",
   "allSections":[  

   ],
   "labourerBean":{  
      "gender":0,
      "enrolmentDate":"2018-06-08T07:08:21.296Z",
      "epfMemberId":"2",
      "firstName":"Kedar",
      "lastName":"jadhav",
      "dob":"1990-11-30T18:30:00.000Z",
      "phone1":"1236547896",
      "panNumber":"1452368545"
   },
   "companyRetentionBonus":0,
   "isRootAdmin":true,
   "from":"manage_labourers"
}

1 个答案:

答案 0 :(得分:0)

最简单的方法是将您的JSON有效负载格式化为单个字符串,即

{"addLabourerToSpecificShift":false,"isEarlySubmit":true,"isExistinglabourer":false,"task":"add","currentDate":"2018-06-08T07:08:21.296Z","allSections":[],"labourerBean":{"gender":0,"enrolmentDate":"2018-06-08T07:08:21.296Z","epfMemberId":"2","firstName":"Kedar","lastName":"jadhav","dob":"1990-11-30T18:30:00.000Z","phone1":"1236547896","panNumber":"1452368545"},"companyRetentionBonus":0,"isRootAdmin":true,"from":"manage_labourers"}

然后您就可以使用CSV Data Set Config\n分隔符一样使用:

JMeter CSV Data Set Config

并在需要时将值称为${json}

更简单的选择是直接在__StringFromFile()采样器Body Data标签中使用HTTP Request功能,例如:

${__StringFromFile(/path/to/your/csv/file,,,)}

JMeter StringFromFile

__StringFromFile()函数每次调用时都会从指定文件中读取下一行,这样您就可以轻松地参数化您的请求