How to read pre-defined values from a csv file and replace them with the variables in the "Text to send" field in JMeter?

Viewed 11

To achieve:- To send the below-mentioned string to a server every 10 secs.

Text to Send:- '''XXXXXXX,XXXXXXX,XXXXXXXX,${packettype},${msgid},${pcktsts},${__threadGroupName},TSXXTSXXXX,${gpsfix},31082022,${__groovy(new Date().format("HHmmss", TimeZone.getTimeZone('UTC')),)},${lat},${latdir},${long},${longdir},${speed},${head},${sat},${alt},${pdop},${hdop},${network},${ignsts},${mpsts},${mivolt},${ibvoltusg},${emsts},${tampalt},31,404,86,7b73,b74a,86,02a2,7b73,49,4d0a,7d0b,49,1948,7b73,59,Ffff,0000,100000,001,${frame},0.0,0.0,${ddist},()*${checksum}'''

Here in the above text, I want the variables to be replaced automatically on every request with the data pre-defined (against that particular variable) in a CSV file.

Note:- I want to send the above data/string through a TCP Sampler. Suggestions are appreciated if someone could suggest a better way of achieving the same.

1 Answers

If you have a variable from the CSV file which contains references to other JMeter Variables or functions you need to wrap it into __eval() function

For example:

  1. You have foo variable with the value of bar
  2. You have entry in the CSV file which looks like ${foo}
  3. You defined some-variable in the CSV Data Set Config which returns this ${foo} entry from the file

then:

  • ${some-variable} will return ${foo}
  • and ${__eval(${some-variable})} will return bar

enter image description here

More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

Related