How to write the extracted values to the local file?



Solution 1:


Step 1: Add the regular expression extractor / boundary based extractor to the sampler.

Step 2: add the bean-shell post processor to the same sampler.

Step 3: add the following script to the bean-shell post processor as a body.

import java.io.FileOutputStream;

import java.util.Map;

import java.util.Set;

FileOutputStream out = new FileOutputStream("path of the file along with name of the file (/home/madhusudhana/Desktop/Results.csv)", true);

String newline = System.getProperty("line.separator");

Set variables = vars.entrySet();

for (Map.Entry entry : variables)

{

if (entry.getKey().startsWith("organization")) // organization is reference parameter in regular extracter

{

out.write(entry.getValue().toString().getBytes("UTF-8"));

out.write(newline.getBytes("UTF-8"));

out.flush();

}

}

out.close();

Step 4 : Run the script.
Step 5: navigate to the path so that you can see the file which has extracted values init.

Note: refer the following screenshot.




solution 2:



Step 1: Add the regular expression extractor / boundary based extractor to the sampler.

Step 2: add the bean-shell post processor to the same sampler.

Step 3: add the following script to the bean-shell post processor as a body. (see the below screen shot)


tokenID = vars.get("token");       // token is reference parameter in regular extractor

f = new FileOutputStream("path of the file along with name of the file (/home/madhusudhana/Desktop/Results.csv)", true);

p = new PrintStream(f); 

this.interpreter.setOut(p); 

print(tokenID);


f.close();


Step 4 : Run the script.

Step 5: navigate to the path so that you can see the file which has extracted values init.

Note: refer the following screenshots.








No comments:

Post a Comment