以下请求是基本请求,
def add_stu(request):
if request.method == 'GET':
return render(request, "add_student.html")
else:
user_form = UserForm(request.POST, instance=request.user)
profile_form = studentForm(request.POST, instance=request.user.student)
user_form.save()
profile_form.save()
我想在单个JMeter请求中使用如下所示的多个(1000)'子'部分来模拟这个: 它应创建具有唯一值的1000个数据集(名称,描述,单元名称,ID,val),然后发布请求。而不是手动创建多个标签,我可以自动化它或创建一个脚本来自动生成它吗?
[
{
"name": "Test1",
"description": "testings",
"unitname": simple,
"ID": 02,
"val": "item"
},
{
"name": "Test2",
"description": "testing",
"unitname": simple3,
"ID": 23,
"val": "item"
}
]
请帮忙吗?
答案 0 :(得分:0)
将以下代码放入"脚本"面积:
import groovy.json.JsonBuilder
import groovy.json.internal.LazyMap
import org.apache.commons.lang3.RandomStringUtils
def data = new ArrayList()
1.upto(1000, {
def entry = new LazyMap()
entry.put('name', 'test' + it)
entry.put('description', RandomStringUtils.randomAlphabetic(10))
entry.put('unitname', 'simple')
entry.put('ID', it)
entry.put('val', 'item')
data.add(entry)
})
def builder = new JsonBuilder()
builder(
data.collect {
[
name : it.get('name'),
descrtiption: it.get('description'),
unitname : it.get('unitname'),
ID : it.get('ID'),
val : it.get('val')
]
}
)
sampler.setPostBodyRaw(true)
sampler.addNonEncodedArgument("", builder.toPrettyString(), "")
勾选Cache compiled script if available
框
groovy
下拉如果是这样,上面的脚本会生成一个JSON Array并将其设置为HTTP Request采样器的正文。
更多信息: