如何基于jmeter中的先前响应值绕过采样器? [英] how to Bypass the Sampler based on previous response value in jmeter?
问题描述
我陷入了一种情况,在这种情况下,我需要验证某个值中前一个采样器的响应,如果该值是[],则我需要触发以下请求,否则切换到另一个采样器.
I have caught up in a situation, where in i need to verify the response of the Previous Sampler for one of the value and if the Value for that is [], then i need to trigger the below request or else then switch to another Sampler.
Flow:
Check Response of Sampler for One of the attribute
IF(attribute value==[])
Execute the Sampler under IF Conditions.
ELSE
New Sampler
样品响应: {"id":8,"merchant_id":"39","title":"Shirts-XtraLarge","subtitle":null,"price":110,"description":null,"images":"image_thumbs" :[[]],"options":[],"options_available":[],"custom_options":[]}
Sample Response: {"id":8,"merchant_id":"39","title":"Shirts-XtraLarge","subtitle":null,"price":110,"description":null,"images":"image_thumbs":[[]],"options":[],"options_available":[],"custom_options":[]}
我需要检查custom_options属性是否为空!如果为空,请执行一些操作,如果不为空,请执行其他操作!
I need to check if the attribute custom_options is empty or not! If Empty do some actions and if not empty do some other action !
需要条件来模拟这一点!
Need if condition to simulate this!
帮助很有用!
推荐答案
选择切换控制器
- 将 JSR223 PostProcessor 添加为返回您JSON的请求的子代
-
将以下代码放入脚本"区域:
- Add JSR223 PostProcessor as a child of the request which returns your JSON
Put the following code into "Script" area:
def size = com.jayway.jsonpath.JsonPath.read(prev.getResponseDataAsString(), '$..custom_options')[0].size()
if (size == 0) {
vars.put('size', 'empty')
} else {
vars.put('size', 'notempty')
}
将切换控制器添加到您的测试计划中,并使用${size}
作为切换值"
Add Switch Controller to your Test Plan and use ${size}
as "Switch Value"
添加另一个简单控制器作为交换控制器的子代,并为其赋予notempty
名称.将与不为空的"custom_options"相关的请求放在该notempty
简单控制器下.
Add another Simple Controller as a child of the Switch Controller and give notempty
name to it. Put request(s) related to not empty "custom_options" under that notempty
Simple Controller.
更多信息: JMeter轻松的选择语句
这篇关于如何基于jmeter中的先前响应值绕过采样器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!