简体   繁体   中英

How to replace multiple pipleline with comma using CSV file in Jmeter

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.

在此处输入图片说明

  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替换字符串中的char

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

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.

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