使用 JMeter 中值列表中的请求值
我确信我过去已经这样做过,但不知何故我不知道如何做;-) 所以,这是我的问题:
我正在尝试创建一个 JUnit 测试计划,其中通过更改特定参数来修改每次迭代的 HTTP 请求。因此,例如,在五次迭代中,我希望发出以下 HTTP 请求:
http://localhost:8080/test/foo.html?id=1
http://localhost:8080/test/foo.html?id=2
http://localhost:8080/test/foo.html?id=3
http://localhost:8080/test/foo.html?id=4
...
我想为测试计划全局配置标识符值,并在 HTTP 请求采样器中使用它们,如下所示:
Path: /test/foo.html?id=${categoryId}
现在的问题:如何配置标识符全局值(我不想想要使用StringFromFile
)以及如何在采样器中引用它们?
I'm sure I've already done this in the past but somehow I cannot figure out how ;-)
So, here's my problem:
I'm trying to create a JUnit test plan in which a HTTP request is modified each iteration by altering a specific parameter. So, for example in five iterations I want the following HTTP requests to be made:
http://localhost:8080/test/foo.html?id=1
http://localhost:8080/test/foo.html?id=2
http://localhost:8080/test/foo.html?id=3
http://localhost:8080/test/foo.html?id=4
...
I want to configure the identifier values globally for the test plan and use them within the HTTP request samplerer like this:
Path: /test/foo.html?id=${categoryId}
The question now: How do I configure the identifiers values globally (I do not want to use StringFromFile
) and how do I reference them in the sampler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有多种方法可以做到这一点。
假设您有一个值数组,您可以:
参数”,创建一个条目
对于每个用户/循环
用于创建数组的脚本,选择
随机一个并填充您的
变量
您完全按照列出的方式引用它们:
${varName}
There are several ways you can do this.
Given you have an array of values you could:
Parameters", creating one entry
for each user/loop
script to create the array, select
one at random and populate your
variable
You reference them exactly as you have listed:
${varName}
要从列表中获取随机变量值,首先将列表或可用值声明为用户变量,并带有前缀和增量索引:
然后,您可以从列表中获取随机值,将前缀与区间内的随机索引连接起来:
请查看此答案以获取完整说明。
To obtain a random variable value from a list, first declare as User variables the list or available values, with a prefix and a incremental index:
Then you can obtain a random value from the list concatenating the prefix with a random index in the interval:
Take a look to this answer for complete explanation.
关于实现
${__StringFromArrayAtRandomIndex('3', '2', '54', '42')}
。假设您可以使用例如 BeanShell Sampler / BeanShell PostProcessor 带有一些代码。
例如:
设置源变量(通过例如用户定义变量):
使用添加 BeanShell Sampler/PostProcessor 和以下代码:
${categoryId}
。Concerning implementing
${__StringFromArrayAtRandomIndex('3', '2', '54', '42')}
.Suppose you can easily implement your scenario using e.g. BeanShell Sampler / BeanShell PostProcessor with a bit of code.
E.g.:
Set your source variable (via e.g. User Defined Variables):
(i.e. use comma as delimiter, no spaces before and after comma).
Use add BeanShell Sampler/PostProcessor with the following code:
${categoryId}
.没有变量的最简单解决方案可以使用 vars.getIteration() 来完成:
The Simplest solution without variables can be done using
vars.getIteration()
: