从HTTP Sampler到Beanshell PostProcessor的响应中获取变量值 [英] Get variable value from the response of an HTTP Sampler to Beanshell PostProcessor
本文介绍了从HTTP Sampler到Beanshell PostProcessor的响应中获取变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在HTTP Sampler中,响应我有一个javascript变量
int a = 1;
我想在BeanShell后处理器中获得这个'a'的值,我该如何获得它在JMeter?
解决方案
请注意
参考文献:
In HTTP Sampler,response I have a javascript variable
int a=1;
I want to get the value of this 'a' in BeanShell Post Processor, How do I get it in JMeter?
解决方案
Be aware that since JMeter 3.1 it is recommended to use Groovy for any form of scripting in JMeter so I would suggest going for JSR223 PostProcessor instead. The relevant Groovy code would be something like:
def text = prev.getResponseDataAsString()
log.info('Response text is' + text)
def match = text =~ /int a=(\d+)/
if (match.find()) {
def value = match.group(1)
log.info('------------------')
log.info('a value=' + value)
vars.put('a', value)
}
Demo:
References:
这篇关于从HTTP Sampler到Beanshell PostProcessor的响应中获取变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文