Writing Variables using Beanshell Sampler in JMeter into a txt/csv file

ganvartin

My requirement is to write two values using 2 Beanshell Samplers used in different steps, in a single line and separated by a comma But the second variable is written on a new line

I have two different Beanshell Samplers at different steps. First one captures Variable 1 and writes it in a file Second one captures Variable 2 and writes it in the file

First Code:

String path= FileServer.getFileServer().getBaseDir() + "//P_IssuePolicy.txt";
SubmissionNum= vars.get("CP_SubmissionNumber");
EMailID= vars.get("P_emailID");
f = new FileOutputStream(path, true);
p = new PrintStream(f);
this.interpreter.setOut(p); 
p.println(EMailID+","+SubmissionNum);
f.close();

Second Code:

String path= FileServer.getFileServer().getBaseDir() + "//P_IssuePolicy.txt";
Policynumber= vars.get("CP_Policynumber");
f = new FileOutputStream(path, true); 
p = new PrintStream(f);
this.interpreter.setOut(p);
p.println(","+Policynumber);
f.close();

Expected Result:

 [email protected],12345601,12345602

Actual Result:

 [email protected],12345601

 ,12345602
user7294900

Instead of println which adds new line use print

 p.print(EMailID+","+SubmissionNum);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

JMeter - Exception when using Beanshell as JSR223 Sampler with file

Unable to append to next line in a file through beanshell assertion sampler in Jmeter

Store Jmeter sampler properties value using beanshell preprocessor

Jmeter, BeanShell Sampler and Summary Report

Verify the file is exist on a location in jmeter using beanshell

Error in Beanshell Sampler JMeter for parsing RegularExpressionExtractor

Parsing string to integer in BeanShell Sampler in JMeter

Jmeter and global Beanshell variables

Update Jmeter variables with beanshell

JMeter Beanshell sampler that runs when HTTP Request Sampler fails

In Jmeter how do I set a variable number of threads using a beanshell sampler variable?

Writing to a file named with variables in distributed JMeter testing

Execute a file using OS sampler in JMeter on a RHEL 8 Machine

upload a file using jsr223 sampler getting failure on JMeter

Jmeter: Access all results from all threadGroups from JSR223 Sampler or BeanShell Sampler in TeardownThread

Writing to txt file using variables

JMeter custom soap sampler to use variables

How to write data at particular cell in excel/csv file in jmeter using beanshell?

Jmeter extract a value using BeanShell PostProcessor

BeanShell Post Processor parse Json using Jmeter

How to set ChromeProfile using Jmeter WebDriver Sampler?

JMeter saving document to MongoDb with Java BeanShell: Problem in JSR223 script Sampler

How to get Sampler Body data from beanshell Pre-Processor - JMeter

How to loop an HTTP request and update the variables each time in Jmeter BeanShell

Is there a way to dynamically set variables values for the post request with jmeter beanshell preprocessor

Jmeter Debug Sampler Not Showing Regular Expression Extractor variables

Issue with Jmeter Beanshellcode for file writing

JMeter / Beanshell "Error invoking bsh method: eval Sourced file:"

JMeter Beanshell Get Text File Size Save to Variable