1
  1. I've added a regular expression extractor as a child element of the HTTP request
  2. From the regular expression extractor I've created a new variable called variabletest.
Name of created variable: variabletest
Regular Expression: "id":"(.+?)"
Template $1$
Match No: 1
  1. I add Debug sampler to ensure it return the correct output.

    • Request 1
      • Regular Expression Extractor (Name of created variable: variabletest)
      • Debug sampler
    • Request 2
    • HTTP Cookie Manager
  2. Then, I added a HTTP Cookie Manager at the bottom of the test plan. Where it configured as below.

Name: Value Domain Path: Secure
afiliation ${variabletest} localhost:8080 /sample

For the Request Body of request 1,2,3... instead of showing the correct extracted variable value, it just show afiliation=${variabletest}

When I run the test, the ${variabletest} is show as empty value, it seems like it doesn't consider the extracted variables.

Then, when I increase the loop count to 2, I noticed, that the extracted variable only available for use in the second iteration of the test plan and not in the first iteration.

Any ideas?

1 Answer 1

1

I can think only of incorrect placement of the Regular Expression Extractor, i.e. check JMeter Scoping Rules chapter

If you have the Regular Expression Extractor at the same level as your Samplers - it will be executed after each Sampler so

  1. It's executed after 1st HTTP Request sampler and extracts the variable normally
  2. It's executed after Debug Sampler and fails to extract the variable overwriting the previous variable value with the empty or default value

So I think if you move it to be the child of the 1st HTTP Request sampler it should resolve your issue.

enter image description here

It also appears that you're using regular expressions to fetch the id from JSON response which is not the best idea as JSON is not a regular language, maybe it worth considering migrating to JSON Extractor instead?

1
  • Hi, thanks for the suggestions. I've tried and unfortunately, it still return an empty value eventhough i can see the correct output being displayed in the debug sampler. Perhaps do you have any idea or what could be the problem?
    – Akmal
    Jan 9, 2023 at 4:41

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.