JMeter:在beanshell后处理器中使用正则表达式提取器值 [英] JMeter: Using a regex extractor value in beanshell post processor

查看:576
本文介绍了JMeter:在beanshell后处理器中使用正则表达式提取器值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个主题上找到了两个类似的主题,但是应用到目前为止我发现的解决方案并没有运气.我正在学习JMeter,正在做的一个练习是(1)创建一个简单的HTTP请求,(2)使用正则表达式提取器提取CSRF令牌,然后(3)写出提取的通过bean脚本传递到jmeter.log.

I found a couple of similar threads on this topic but haven't had any luck applying solutions I've found so far. I'm in the process of learning JMeter, and an exercise I've been given is to (1) create a simple HTTP request, (2) extract the CSRF token with a Regular Expression Extractor, then (3) write out the extracted token via a beanshell script to the jmeter.log.

因此提取令牌很简单:

So extracting the token is straightforward:

由于我接下来需要获取该值并通过beanshell脚本运行它,因此我假设使用BeanShell PostProcessor将是这里的方法.我已经尝试了以下几种方法:

Since I need to next take that value and run it through a beanshell script, I assumed using a BeanShell PostProcessor would be the way to go here. I've tried a few variations of the following:

log.info(令牌为:" + vars.get("token"));

log.info("The token is: " + vars.get("token"));

测试运行正常,但是随后出现在结果日志中:

The test runs fine, but then this appears in the resulting log:

INFO o.a.j.u.BeanShellTestElement:令牌为:空

INFO o.a.j.u.BeanShellTestElement: The token is: null

最后,由于我了解后处理器的运行顺序是颠倒的,所以我将其放置在我的正则表达式提取器上方(尽管我已经尝试过将其反转,但效果没有差别):

Lastly, since I understand the post processor runs upside-down in order, I placed it above my regex extractor (though I've tried it reverse, with no difference in effect):

我确定我犯了一些菜鸟错误,但是我开始使用谷歌搜索圈出一圈.任何建议将不胜感激!

I'm sure I'm making some noob mistake, but I'm starting to run in circles with my googling. Any advice would be hugely appreciated!

推荐答案

Beanshell后处理器必须在正则表达式提取器之后,否则该变量尚不可用

The Beanshell post processor must be after the regex extractor otherwise the variable is not yet available

这篇关于JMeter:在beanshell后处理器中使用正则表达式提取器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆