0
votes

New to JMeter, and I'm probably missing some simple thing but I can't find it anywhere.

I'm trying to log into a web application so I send a GET request to the home page to retrieve the csrf token and then I use the regular expression extractor to retrieve it: Post process extractor

I then try to place the extracted token into the POST request: RegEx User Parameter

But the extracted token doesn't show up in the request sent via the View Results Tree. Only the UserId and Password are passed which I manually defined: Missing token

My regular expression is finding a match as you can see here: enter image description here but even if it wasn't finding a match, it should still pass "NotFound" correct?

Any help is greatly appreciated!

Edit: Added a Debug Sampler and it is correctly showing the variable Token with it's correct value. So Token just isn't being added to the request via the RegEx User Parameter Pre Processor.

1

1 Answers

1
votes

It's difficult to see what you're doing without seeing the LoginPage step, but you need to make sure you are adding the csrf token you've extracted in the right place. Typically it could be as a query param, part of a post body or an http header.

As you can see the token has been extracted from your initial response in the Debug sampler, there must be something wrong in how or where the token is being applied to the LoginPage request. (As you say the RegEx User Parameter Pre Processor isn't adding it)

I've never used the PreProcessor and the Jmeter documentation explanation is a bit vague on what it does, but you can add the variables into your request without it using the variable saved for the capture groups - for input name this will be ${Token_g1} and for value it will be ${Token_g2} - which you will be able to see from the Debug Sampler. You'll need to add a Header or Cookie Manager to the Login Page element if this is where the token is.

By setting the template in the Extractor to $1$$2$ you create a variable with the name and value concatenated together. I'm not sure why you would need this, and I would guess that the name doesn't change - in which case you can just use capture group 2, or if you want to use the Variable name Token then update your template to be $2$