user3149750
user3149750

Reputation: 17

Values that written in the CSV file is on a loop. I only need one single string (Jmeter)

I have written a simple beanshell script to get few values that I have selected with a regular expression and write them into a CSV file in a string.

nic = vars.get("NicNo01");
name = vars.get("Name01");
loanId = vars.get("Loan_Id");

f = new FileOutputStream("C:/Users/User/Desktop/scripts/Final/result.csv", true);
p = new PrintStream(f);
this.interpreter.setOut(p);
print(nic + "," + name + "," + loanId);
f.close();

The data is been written in a loop with few null values and at the end the final string is the correct one I need. I have not used any loop controllers or the thread group is not on a loop. This is a part of the CSV file data.

null,null,null
null,null,null
588583492V,A B C Fernando,null
588583492V,A B C Fernando,null
588583492V,A B C Fernando,null
588583492V,A B C Fernando,127180

why is there a loop like data export? And How can I get only the correct final string?

Upvotes: 0

Views: 449

Answers (2)

timbre timbre
timbre timbre

Reputation: 13970

How about writing it only when all variables are not null:

nic = vars.get("NicNo01");
name = vars.get("Name01");
loanId = vars.get("Loan_Id");

if(nic == null || name == null || loanId == null)
    return;

// otherwise write to file

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 168072

In case of high number of threads Beanshell may not be able to store the data properly due to performance issues. Try switching to JSR223 Post Processor and use Groovy as scripting language

Another option could be using sample_variables property. Add the following line to user.properties file (lives under /bin folder of your JMeter installation)

sample_variables=NicNo01,Name01,Loan_Id

and upon JMeter restart variables values will be added to JMeter's .jtl results file.

Upvotes: 0

Related Questions