How to send JSON data from csv file in POST method?

∥☆過路亽.° 提交于 2019-12-24 03:25:51

问题


In my project I am using Jmeter for load testing.
I have created a test plan as follows:

  1. Login to the application using a csv file which has 10 unique username and password (successfully done)
  2. A regular expression extractor will get the session id from the response which will be used in the next sampler for submitting a request. (sessionId extracted successfully)
  3. The next sampler will submit a request. This sampler accepts two parameters: sessionId & licenseRequest. A little details for the java-script is as follows:

    url: "groovy/enqueue",
    type: "POST",
    global: false,
    data: {sessionId: uSessionId, licenseRequest: JSON.stringify(requestJSON) },
    dataType: "text",
    

For submitting the request I have created a csv file.
The csv is similar like this:

Entry 1:
{"activations":["<activation-code>","<activation-code>"],"email":"<emailIdofUser>","csvEntries":[{"model":"<modelname>","serial":"<serialNo>"}],"comment":"testing jmeter"}

What I have found out that while submitting the request in th second sampler the post request is malformed:

POST data:
sessionId=vZNjFjW38cid&licenseRequest=%3CEOF%3E

As you can see the licenseRequest's value is not correct. It is sending the EOF, which is not desired.


回答1:


Ensure that you have the CSV Data Set Recycle on EOF and Stop Thread on EOF values correctly:

  • if you plan to iterate over the file more than once you must set Recycle on EOF = True (i.e. instruct jmeter to move back to the top of the CSV file);
  • set Stop Thread on EOF = False if you are using a loop controller, Stop Thread on EOF = True if you are using a while controller and want to stop after reading the whole csv dataset;
  • in case if you need that each of N threads reads and uses single and unique line from csv-file you have to set Sharing mode: Current thread group for CSV Data Set Config (number of csv-entries should be in this case the same as threads number, or Recycle on EOF? False should be set otherwise);
  • in case if you need that each of N threads reads and uses all lines from csv-file you have to set Sharing mode: Current thread for CSV Data Set Config.

Don't forget to look into jmeter.log or use Log Viewer to detect any issues with csv usage.


The simplest case is like the following:


Test Group
Number of Threads = 10
    CSV Data Set Config (User Logins)
    Filename: ... (your csv-file should have 10 entries)
    Recycle on EOF = False
    Stop Thread on EOF = True
    Sharing Mode = All threads
    CSV Data Set Config (License Request)
    Filename: ... (your csv-file should have 10 entries)
    Recycle on EOF = False
    Stop Thread on EOF = True
    Sharing Mode = All threads
    Login Sampler
    License request Sampler

This will produce 10 threads each with separate login-entry and license-request-entry from csv's.



来源:https://stackoverflow.com/questions/14938950/how-to-send-json-data-from-csv-file-in-post-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!