本文介绍了有没有一种方法可以为jmeter中的所有发布请求添加请求参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在测试计划中添加 Beanshell预处理器(与您的HTTP请求)
Add Beanshell PreProcessor to your Test Plan (at the same level as your HTTP Requests)
我需要在jmeter中的每个帖子请求中添加一个令牌.我尝试使用Http Request默认值,但是它不起作用.
I need to add a token to each post request in jmeter. I have tried using Http Request defaults but it isn't working.
推荐答案使用某些脚本可以实现.
It is possible with some scripting.
将以下代码放入预处理器的脚本"区域:
Put the following code into the PreProcessor's "Script" area: sampler.addArgument("token", "token_value");
用您的实际数据替换token和token_value
Replace token and token_value with your actual data
运行测试时,将在每个采样器之前执行Beanshell PreProcessor,并将参数添加到每个范围内的HTTP请求.
When you run the test Beanshell PreProcessor will be executed before each sampler and add the parameter to each HTTP Request in scope.
参考文献:
- sampler代表HTTPSamplerBase类实例,请参见 HTTPSamplerBase JavaDoc 有关方法和字段的详细信息
- 如何使用BeanShell:JMeter最喜欢的内置组件-有关通过一些示例在JMeter测试中使用Beanshell脚本的全面信息
- sampler stands for HTTPSamplerBase class instance, see HTTPSamplerBase JavaDoc for detailed information on methods and fields
- How to Use BeanShell: JMeter's Favorite Built-in Component - comprehensive information on using Beanshell scripting in JMeter tests with some examples
更多推荐
有没有一种方法可以为jmeter中的所有发布请求添加请求参数?
发布评论