JMETER - response assertion -> Response was null

Viewed 21

I have checked several options how to validate response and it still not works in my case. As you can see (Debug sampler), for last_name regex works and I receive some values, but if I want to reuse this response as "Response assertion", test failed, because I receive "Response was null".

JSON Extractor for last_name

Response assertion

Test failed

Also, I would like to count objects in "data", so I used http://jsonpath.herokuapp.com/?path=$..book[0,1] to make sure, the JSON file is correct. But "Debug sampler" shows me nothing :( so test failed again

Count of objects Result

Any idea how to solve this problem please ?

JSON:

{
"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"
    }
],
1 Answers
  1. You need to tick Compute concatenation var in JSON Extractor, otherwise you will get 2 separate JMeter Variables:

    lastName_1=Lawson
    lastName_2=Ferguson 
    

    enter image description here

  2. In addition to point 1 you need to use lastName_ALL in the Response Assertion

  3. You need to switch from Matches to Substring in "Pattern Matching Rules" of the Response assertion

Demo:

enter image description here

More information: How to Use the JSON Extractor For Testing

Related