-2

I'm facing some issue while creating the script to print input test data+response for that data. I want to print input test data also, for example:

cards
98765432
98765432

Results CSV file:should be

Cards,Results
98765432,PASS
98765432,FAIL

How can I print like above? My code is

import java.io.File;
import org.apache.jmeter.services.FileServer;

Result = "FAIL";
Response = prev.getResponseDataAsString();

if(Response.contains("fullCardNo"))
    Result = "PASS";
fullCardNo =vars.get("fullcards");
f = new FileOutputStream("F:\\Java_Applications\\apache-jmeter-3.1\\bin\\FullCardsResults.csv",true);
p=new PrintStream(f);

this.interpreter.setOut(p);
p.println((${cards})+","+fullCardNo + "-" + Result);
f.close();
p.close();

By this above script,my results file showing empty, there is no data in that file.

halfer
  • 19,824
  • 17
  • 99
  • 186
Rajesh Om
  • 483
  • 2
  • 15
  • 39
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](https://meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer May 27 '17 at 14:23

2 Answers2

0

I've found the answer where error in my script only,just i've changed and copy ,paste fullCardNo =vars.get("fullcards"); in above the Result="FAIL" as below and below is the code works for me.

import java.io.File;
import org.apache.jmeter.services.FileServer;
cardsnumber =vars.get("cards");
Result = "FAIL";
Response = prev.getResponseDataAsString();
if(Response.contains("fullCardNo"))
    Result = "PASS";
fullCardNo =vars.get("fullcards");
f = new FileOutputStream("F:\\Java_Applications\\apache-jmeter-3.1\\bin\\FullCardsResults.csv",true);
p=new PrintStream(f);

this.interpreter.setOut(p);
p.println(cardsnumber+","+fullCardNo + "-" + Result);
f.close();
p.close();

Please follow above code then it is possible to print input variables also in results csv file as i asked in the question.

Rajesh Om
  • 483
  • 2
  • 15
  • 39
0

It is recommended to avoid scripting where possible so I would suggest using Sample Variables property instead

Given you set sample_variables property by adding the next line to user.properties file (located in the "bin" folder of your JMeter installation)

sample_variables=cards,fullcards

or pass them to JMeter startup script via -J command-line argument like:

jmeter -Jsample_variables=cards,fullcards -n -t test.jmx -l result.csv

Your result.csv file will contain 2 extra columns where ${cards} and ${fullcards} values will be present. See Apache JMeter Properties Customization Guide guide for more information on precisely tuning your JMeter instance(s) via properties.


If you have to do something which requires scripting make sure you are using the most performing option which is JSR223 Test Elements with Groovy language as of now.

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