首页 > 解决方案 > How to take values of Jmeter variable in coma separated way

问题描述

I'm hitting a rest Api through http GET request in jmeter. the url is like http://hostName:port/searchParameter=value1,value2,value3

the value1, value2 ... are taken from a file which is like

File.csv value1 value2 value3

this csv file is not really coma seperated values they are in separate lines. Now how to achieve this

标签: resttestinggroovyjmeter

解决方案


JMeter doesn't provide a suitable test element so you will have to go for __groovy() function and some custom scripting.

I can think of using File.readLines() function to read the contents of your file into memory followed by join() function to convert the array into a comma-separated string.

The final syntax would be:

${__groovy(new File('File.csv').readLines().join('\,'),)}

Demo:

enter image description here

Check out Apache JMeter Functions - An Introduction article to get familiarized with JMeter Functions concept.


推荐阅读