- I've added a regular expression extractor as a child element of the
HTTP request
- 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 |
I add Debug sampler to ensure it return the correct output.
- Request 1
- Regular
Expression Extractor
(Name of created variable:variabletest
) - Debug sampler
- Regular
- Request 2
- HTTP Cookie Manager
- Request 1
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
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
- It's executed after 1st HTTP Request sampler and extracts the variable normally
- 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.
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?
-
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– Akmal2023年01月09日 04:41:35 +00:00Commented Jan 9, 2023 at 4:41