0

I had a scenario where I need to write correlation values in a CSV file. And the easiest way I had come up with is the below code in answer section.

More suggestions are appreciated.

4 Answers 4

2

There is a plugin called Flexible file writer You can use that it is efficient and easy to implement explained here.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I find this method much simple than others.
1

Be aware that starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for any form of scripting so consider migrating to the JSR223 PostProcessor and the following code:

new File('FILEPATH/filename.csv') << vars.get('PARAM_1') << ',' << vars.get('PARAM_2') << System.getProperty('line.separator')

However this approach will work only if no concurrency assumed, if the PostProcessor will be executed by 2 or more concurrent threads you may run into a race condition when multiple threads will be writing into the same file resulting in data corruption.

So I would recommend declaring your PARAM_1 and PARAM_2 as Sample Variables and storing them into a file using i.e. Flexible File Writer

1 Comment

Thanks for this approach. Flexible file writer looks more simple than any other way.
0

Add this below code in Bean Shell Post Processor

a = vars.get("PARAM_1"); // PARAM_1 is parameter/correlation variable
b = vars.get("PARAM_2"); // PARAM_2 is parameter/correlation variable
f = new FileOutputStream("FILEPATH/filename.csv", true);
p = new PrintStream(f); 
this.interpreter.setOut(p); 
print(a +","+ b);
f.close();

Comments

0

Dont use Beanshell sampler. Use JSR sampler and get the variables as usual like vars.get("variableName");

In Bean shell sampler it wont work.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.