1

I'd like to prefix this question with the fact that i'm a novice when it comes to Jmeter and Regex.

I have created a test plan for an ASP .Net application, which consists of a GET request, with a Regular expression extractor to grab a token, then a POST request, with a RegEx User Parameter to take the extracted token and use it in the request:

enter image description here

In the get request's respnse, there is a value of __RequestVerificationToken, which i am capturing with the following Regex (tested in tree Listner and is Validated):

(?<=Set-Cookie: __RequestVerificationToken=).{108}

So, it looks for "__RequestVerificationToken=" then gets the 108 characters after it.

enter image description here

Regular expression extractor:

enter image description here

Parameters in POST Request:

enter image description here

The RegEx user parameter i'm using is:

enter image description here

But when i run the test, the request post data returns:

enter image description here

I've used https://www.regextester.com/ for testing my RegEx and it correctly gets the token, so i'm wondering if JMeter just doesn't accept this?

Note: apologies for using images rather than text, i couldn't think of a good way to show the data.

2
  • I am not sure your regexp is valid. There is much easier way to capture the token since it is between = and ;. Can you test your expression here regex101.com and save your trials and share as saved link?
    – Alexey R.
    Commented Feb 12, 2020 at 18:29
  • Hi, Thanks for responding. I've tested it on the suggested link. It does look to be matching. please see here: regex101.com/r/1ljlXj/1
    – coltest123
    Commented Feb 13, 2020 at 7:01

3 Answers 3

3

It looks like your __RequestVerificationToken comes as a HTTP Cookie hence it makes sense to use HTTP Cookie Manager

  1. Add the next line to user.properties file (lives in "bin" folder of your JMeter installation)

    CookieManager.save.cookies=true
    
  2. Add HTTP Cookie Manager to your Test Plan
  3. That's it, now you can access the token value as ${COOKIE____RequestVerificationToken} where required

Check out HTTP Cookie Manager Advanced Usage - A Guide article for more information

2
  • "Add the next line to user.properties file" which line?
    – Alexey R.
    Commented Feb 13, 2020 at 10:36
  • 1
    Thanks for the catch, updated
    – Dmitri T
    Commented Feb 13, 2020 at 10:43
0

Can you try this for regex:

__RequestVerificationToken=(.+?);
1
  • Hi, The above RegEx has given me the desired result, if i change the RegEx extractor template to $1$ in my scenario. Thanks for the suggestion!
    – coltest123
    Commented Feb 13, 2020 at 7:09
0

It appears that you are expecting a valid JSON, so instead of RegEx, you could use JSON Extractor and/or JSON Assertion, for which extra spacing will not matter.

Example if response data is

{"RequestVerificationToken":"12345"}

and specify JSON extractor and place under the HTTP Header manager and send JSON path as $.RequestVerificationToken and you got the result variable RequestVerificationToken with Expacted value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.