Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Jmeter json extractor only passes default value

I am using JMeter’s JSON extractor to pass a variable id from one request to another.

This is the response of the first request (https://reqres.in/api/users?page=2):

{
  "page": 2,
  "per_page": 6,
  "total": 12,
  "total_pages": 2,
  "data": [
    {
      "id": 7,
      "email": "michael.lawson@reqres.in",
      "first_name": "Michael",
      "last_name": "Lawson",
      "avatar": "https://reqres.in/img/faces/7-image.jpg"
    },
    {
      "id": 8,
      "email": "lindsay.ferguson@reqres.in",
      "first_name": "Lindsay",
      "last_name": "Ferguson",
      "avatar": "https://reqres.in/img/faces/8-image.jpg"
    },
    {
      "id": 9,
      "email": "tobias.funke@reqres.in",
      "first_name": "Tobias",
      "last_name": "Funke",
      "avatar": "https://reqres.in/img/faces/9-image.jpg"
    },
    {
      "id": 10,
      "email": "byron.fields@reqres.in",
      "first_name": "Byron",
      "last_name": "Fields",
      "avatar": "https://reqres.in/img/faces/10-image.jpg"
    },
    {
      "id": 11,
      "email": "george.edwards@reqres.in",
      "first_name": "George",
      "last_name": "Edwards",
      "avatar": "https://reqres.in/img/faces/11-image.jpg"
    },
    {
      "id": 12,
      "email": "rachel.howell@reqres.in",
      "first_name": "Rachel",
      "last_name": "Howell",
      "avatar": "https://reqres.in/img/faces/12-image.jpg"
    }
  ],
  "support": {
    "url": "https://reqres.in/#support-heading",
    "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
  }
}

In the extractor I named the variable userID and JSON path $..id match no. (1) and default value NoIDFound main sample only
I’m also using a debug sampler and it passes with no problem
Now I’m passing the variable in the second request as (https://reqres.in/api/${userID})

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’m getting 404 Not Found and the request that passed is (https://reqres.in/api/users/NoIDFound)

Can someone tell what i’m doing wrong?

>Solution :

It’s hard to say anything without seeing your Test Plan, I have one assumption, your JSON Extractor might be incorrectly placed. See JMeter Scoping Rules user manual chapter for more information

So if you have the following setup:

enter image description here

it means that the JSON Extractor will be executed after each Sampler, after HTTP Request 1 it will have correct anticipated value and after Debug Sampler it will not because the JSONPath expression won’t match anything and you will end up with the default value.

So make the JSON Extractor a child of the HTTP Request 1

enter image description here

Or use Debug PostProcessor instead of Debug Sampler

More information: How to Use the JSON Extractor For Testing

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading