2

akshaygarg30,akshay.garg+30@jitterbit.com,NewUser,7Iron-hide

I want to make "NewUser" to Activated in the CSV through the beanshell script or through any other way in the jmeter.

1 Answers1

2

You can use __javaScript() function to replace "NewUser" with "Activated" on the fly like:

Given "NewUser" lives in ${status} JMeter Variable:

`${__javaScript("${status}".replace("${status}"\,"Activated"),)}`

Demo:

JavaScript Replace demo


If for some reason you need to replace it in the whole file - it can be done in Beanshell Test Element of your choice using the following code:

import org.apache.commons.io.FileUtils;

File csvFile = new File("/path/to/your/file.csv");
String fileData = FileUtils.readFileToString(csvFile);
fileData = fileData.replaceAll("NewUser", "Activated");
FileUtils.writeStringToFile(csvFile, fileData);

It mostly uses FileUtils class, methods should be self-explanatory. Check out How to Use BeanShell: JMeter's Favorite Built-in Component guide for more information on using Beanshell scripting in JMeter tests.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133