0
votes

I want to replace multiple pipleline with comma using CSV file in Jmeter.

I am using Groovy script. Below is the body data of Jmeter. I am getting multiple values from CSV files and not able to use replaceAll function body data in Jmeter. Any help would be appreciated.

enter image description here

2
where is your groovy script?gagan singh
We can use like that "TemplateIDs": "${TemplateID1}.replaceAll("|",",")", But replaceAll is not working in bodydata.Aditya Kumar
You tried "${TemplateID1.replaceAll("|", ",")}",tim_yates
I tried above, but that's not working.Aditya Kumar

2 Answers

1
votes
  1. You need to use __groovy() function in order to evaluate the Groovy code in HTTP Request sampler body
  2. You need to escape |
  3. You need to escape ,
  4. You need to escape \

Assuming all above the relevant __groovy() function syntax would be:

${__groovy(vars.get('TemplateID1').replaceAll('\\\|'\,'\,'),)}

JMeter Groovy Replace char in string

Also be aware that there is a __strReplace() function which can also do what you need, in this case the syntax would be:

${__strReplace(${TemplateID1},\\|,\,,)}

If you don't have this function it can be installed as a part of " Custom JMeter Functions" bundle using JMeter Plugins Manager

0
votes

replaceAll accepts a regex. you need to escape the pipe char.

replaceAll("\\|", ",")

I tested this in plain groovy and it works. not sure about jmeter integration.