Thursday, July 7, 2016

Create output file using bean shell

import org.apache.jmeter.services.FileServer;
import java.util.Date;
import java.text.SimpleDateFormat;




String DirPath = FileServer.getFileServer().getBaseDir()+File.separator;
String fileName="jmeterDemo.txt";
//log.info(DirPath);
//System.out.println(DirPath);
f = new FileOutputStream(DirPath+"jmeterDemo2.txt", false);
p = new PrintStream(f);


SimpleDateFormat formatter = new SimpleDateFormat( "yyMMddHHmmssZ" ); 
String datetime = formatter.format( new java.util.Date() );

SimpleDateFormat formatter2 = new SimpleDateFormat( "dd/M/yyyy" ); 
String exportedDate = formatter2.format( new java.util.Date() );


for(int i=1;i<=100;i++) {

    if(i==1){
     p.println("id,primar_id,email,first_name,last_name,dob,team_name,dependent_type,start_date,end_date,export_date");
    }
    email="perf_"+datetime+""+i+"@google.com";
    p.println(i+",,"+email+",first,last,01/01/1980,,self,06/23/2016,,"+exportedDate);
}
p.close();
f.close();