简体   繁体   中英

Jmeter - when there are number of threads are running, the variable from JSON extractor is not working sometimes

I am now using Jmeter to run the test of APIs.

The situation is that I have a login Api which will return a token inside response. I use a JSON extractor to save the token as a variable. Then, I use the ${token} is the header of other requests.

However, I found that when I was trying to run 40-50 threads, the ${token} in some threads would be empty, and caused a high error rate.

Therefore, may I ask is there any method to solve it and why?

Thanks very much.

Try saving full response from the Login API, most probably your server gets overloaded and cannot return the token and returning some error message instead.

There are following options:

  1. If you're running JMeter in command-line non-GUI mode you can amend JMeter's Results File Configuration to store the results in XML form and include the response data, add the next lines to user.properties file:

     jmeter.save.saveservice.output_format=xml jmeter.save.saveservice.response_data=true

    and when you run your test next time the .jtl results file will contain response bodies for all the requests.

  2. Another option is using a Listener like Simple Data Writer configured like:

    在此处输入图像描述

    and when you run the test the responses.xml file will contain the response data

Both .jtl results file and responses.xml can be inspected using View Results Tree listener

More information: How to Save Response Data in JMeter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM