在JMeter HTTP POST中参数化POST正文 [英] Parameterize POST body in JMeter HTTP POST

查看:108
本文介绍了在JMeter HTTP POST中参数化POST正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache JMeter针对我们开发的应用程序针对RESTFUL API运行一些性能测试.我有一个端点"api/create/empListJob",它基本上在MongoDB中添加了一个或多个员工记录. POST调用的有效负载如下所示:

I am using Apache JMeter to run a few performance tests against RESTFUL API for an application that we have developed. I have an end point "api/create/empListJob", which basically adds one or more employee records in the MongoDB. The payload for the POST call looks like this:

{
        "employeeList": [
            {
                "first_name": "josh",
                "last_name": "don",
                "age": "25",
                "address": {
                    "street1": "xyz",
                    "street2": "apt-10",
                    "city" : "def",
                    "state" : "CA",
                    "zip" : "95055"
                },
                "deptType": {
                    "deptID": "1",
                    "deptName": "R&D"
                }
            },
            {
                "first_name": "mary",
                "last_name": "jane",
                "age": "22",
                "address": {
                    "street1": "zzz",
                    "street2": "apt-15",
                    "city" : "yyy",
                    "state" : "CA",
                    "zip" : "95054"
                },
                "deptType": {
                    "deptID": "2",
                    "deptName": "HR"
                }
            }
        ]
    }

如您所见,有效负载采用了一组员工数据,并且应该至少有一个员工记录.我有一个要求,我希望JMeter线程组具有10个线程,并且这些线程中的每个线程都应进行并发POST到"api/create/empListJob",以便该主体具有10个唯一的员工记录,从而创建总共100条记录.我可以对有效负载进行参数化的最佳方法是什么?

As you can see, the payload takes a list of employee data, and it should have atleast one employee record. I have a requirement in which i want JMeter thread group to have 10 threads and each of these threads should make a concurrent POST to "api/create/empListJob" such that the body has 10 unique employee records, thus creating a total of 100 records. What is the best way that i could parameterize the payload?

推荐答案

看看 JMeter函数,例如:

  • __threadNum() - returns the number of current thread (virtual user)
  • __Random() - returns a random number in a given range
  • __RandomString() - returns a random string from specified input characters
  • __UUID() - returns random GUID structure

例如,如果您将JSON有效负载更改为:

So for example if you change your JSON payload to look like:

"employeeList": [
  {
      "first_name": "josh-${__threadNum}",
      "last_name": "don-${__threadNum}",
      "age": "25",
      "address": {
          "street1": "xyz",
          "street2": "apt-10",
          "city" : "def",
          "state" : "CA",
          "zip" : "95055"
      },
      "deptType": {
          "deptID": "1",
          "deptName": "R&D"
      }
  },
  {
      "first_name": "mary-${__threadNum}",
      "last_name": "jane-${__threadNum}",
      "age": "22",
      "address": {
          "street1": "zzz",
          "street2": "apt-15",
          "city" : "yyy",
          "state" : "CA",
          "zip" : "95054"
      },
      "deptType": {
          "deptID": "2",
          "deptName": "HR"
      }
  }
]
}

JMeter将创建:

JMeter will create:

- `josh-1` for 1st virtual user
- `josh-2` for 2nd virtual usre
- etc.

请参阅 Apache JMeter函数-简介来熟悉JMeter函数概念.

See Apache JMeter Functions - An Introduction to get familiarized with JMeter Functions concept.

这篇关于在JMeter HTTP POST中参数化POST正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆