1
votes

I am new in jmeter , I have created multiple HTTP Request in a single thread group , Now what i am trying is save all the HTTP Request that is http request with response code 200 in csv file as TestCase pass and http request with response code other than 200 as failed. As I want to execute each and every HTTP request one by one and store result in csv file

here is my beanshell PostProcessor

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

            File f=new File("E:\\apache-jmeter-5.2.1\\apache-jmeter-5.2.1\\bin\\JmeterProResult\\testResult.csv");
            FileWriter fw=new FileWriter(f);
            BufferedWriter bw=new BufferedWriter(fw);
            var rc = prev.getResponseCode();
            if(rc.equals("200")){
             bw.write("test is passed");
            }
            else{
             bw.write("test is failed");
            }
            bw.close();
            fw.close();

which is generating output as show only one result but I run two successful http request

enter image description here

here is mine jmeter structure-- I want to execute each and every HTTP request

enter image description here

here my desired output should look like

enter image description here

1

1 Answers

0
votes
  1. Your approach will work only if you have 1 virtual user, any concurrency will lead to a race condition when 2 threads will be writing the same file resulting in concurrent modification and leading to the data loss
  2. Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so you will need to reconsider your "beanshell" approach in any case

So I would recommend using Flexible File Writer plugin which allows you to store various request/response details into a file in a "safe" way.