Search code examples
jmeterrequestresponsewait

How to wait until specific word is found in response in jmeter?


The json response is:

{
  "status": 11111,
  "data": {
    "mylist": 
    {
      "1": [
        {
          "id": 1,
          "tId": 11
        }],
    
      "2": [
        {
          "id": 2,
          "tId": 12
        },
        {
          "id": 3,
          "tId": 12
  
        },
        {
          "id": 4,
          "tId": 13,
        }
      ]
}

since server takes times to show this response, we want to wait until we see the values under "1" and under "2". How may I achieve this?


Solution

    1. Add 2 JSON Extractors to store the values of id attributes below 1 and 2 into the relevant JMeter Variables

      enter image description here

      enter image description here

    2. Put the whole construction under the While Controller and use the following __groovy() function as the condition:

      ${__groovy((vars.get('1_matchNr') ?: 0  as int) == 0 && (vars.get('2_matchNr') ?: 0  as int) == 0,)}
      

      enter image description here

    3. That's it, JMeter will repeat the request until there are results under mylist containing at least one id attribute