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:
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("The token is: " + vars.get("token"));
The test runs fine, but then this appears in the resulting log:
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!
With regards to your query itself: in order to be able to access the value from the Regular Expression Extractor in the other PostProcessor you need to put the Post Processor below the regular expression extractor.
With regards to approach in general:
The Beanshell post processor must be after the regex extractor otherwise the variable is not yet available