JMeter tutorial 21 - BeanShell Script Part - 2 | Write data to CSV file | BeanShell PostProcessor

Поділитися
Вставка
  • Опубліковано 22 лип 2024
  • This is the twenty-first video of JMeter Tutorial series which covers How to write data to CSV file using BeanShell script
    Learning:
    BeanShell Script to write data to CSV file with if-else condition:
    import java.io.*;
    File f=new File("D:\\jmeterProject\\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();
    BeanShell Introduction - • JMeter tutorial 20-Bea...
    ==================================================================
    Git and GitHub Tutorial Playlist:
    • Git and GitHub Tutorial
    Automation Anywhere Tutorial Playlist:
    • Automation Anywhere A1...
    Subscribe for more tutorials - / @qualityassurancelab7764

КОМЕНТАРІ • 67

  • @BeshoMorise
    @BeshoMorise 4 роки тому +3

    You are the best one in jmeter thank you

  • @rkgramani7896
    @rkgramani7896 2 роки тому +3

    Just a best practise suggestion, instead of import java.io.*, we can use only the classes required
    import java.io.File;
    import java.io.FileWriter;
    import java.io.PrintWriter;
    import java.io.BufferedWriter;
    import java.io.IOException;

  • @kailainathangopathy236
    @kailainathangopathy236 2 роки тому +5

    When we try with bw.newLine(); to store values from multiple iterations, the file is opened everytime and the code is started from the first which is making it to write the response at the first line everytime. So essentially it is replacing the value everytime instead of listing it.
    Got the answer for this.
    Instead of using filrwriter fw = new Filewriter(f);
    We need to use (f,true) to open the file in append mode.

  • @neelimapatnaik4327
    @neelimapatnaik4327 2 роки тому +1

    Hi, can you help me with writing the entire reponse json into csv file.
    I actually need to check the downloaded file, which is in json format in Response.
    and now want this json into CSV format , which ideally dev is duing using javascript.
    Can you let me know how can i do the same using jmeter. I need to convert this json in response to CSV file to validate the file rows and columns from entire JSON response

  • @danielsimiao7949
    @danielsimiao7949 4 роки тому

    Hello, thanks for the video, how to works with coluns name with scenarios that a will access and write results on this csv?

  • @abhishekkr9712
    @abhishekkr9712 3 роки тому

    How can we access and customize scripts based on "passwords" and "captcha " through bean shell scripting ?

  • @arnavpatil583
    @arnavpatil583 3 роки тому +1

    Best tutorial

  • @kumarnitish6552
    @kumarnitish6552 3 роки тому

    How to append multiple results in a single CSV file after invoking multiple HTTP requests which having different if conditions results set?

  • @g.rajendrakumar4847
    @g.rajendrakumar4847 3 роки тому

    Hello, I have saved a Excel file with name (Perfrmon.csv) using type(CSV(Comma Delimited)(*.csv)). Now after writing all the commands in Jmeter (Response OK (200)), I am not getting data printed in the excel file. The CSV excel file is all blank. Please suggest

  • @mrdineshbabu
    @mrdineshbabu 4 роки тому

    Hi, its really good. How can I write the response body json to a csv file?

  • @ankitapatel5659
    @ankitapatel5659 3 роки тому +1

    You're awesome ma'm cant stop writing appreciation comment

    • @abhishekkr9712
      @abhishekkr9712 3 роки тому

      How can we access and customize scripts based on "passwords" and "captcha " through bean shell scripting ?

  • @rockstar8573
    @rockstar8573 4 роки тому

    Hey, thanks for the video,,i have put my sampler under HTTP request and need to fetch json values , but import org.json.*.; Error invoking bsh method: eval In file: inline evaluation of is something I am stuck with.

  • @YeshVihaan
    @YeshVihaan 9 місяців тому

    Would you please let me know how to store my reservation id in a CSV file from the Response body tab

  • @pradeepmishra1523
    @pradeepmishra1523 3 роки тому

    the Above Code is not working in Jmeter4.0 right????

  • @metooyesmum
    @metooyesmum 4 роки тому +1

    excellent...

  • @ayazsabir7729
    @ayazsabir7729 3 роки тому

    I used the same code above but result not written in csv file ...

  • @vinodmisal7891
    @vinodmisal7891 3 роки тому

    Hello hope you are doing well ,Thanks for the such great video,how to write data into a perticular cell and how it works for multiple users?

  • @msk_manandi8033
    @msk_manandi8033 4 роки тому

    how to write the results of 100 threads where I declared in the thread group. it is storing only one thread response.
    Step1: in the thread group declared 100 threads.
    Step2: add Beanshell Postprocessor with bw.newLine(); //even I tried to keep the bean shell script after http request, but no use
    Step3: execute the script.

  • @rupeshbannela492
    @rupeshbannela492 5 років тому +1

    Hi
    Could u please make it css jQuery tester jmeter videos

  • @patriotic_rover4063
    @patriotic_rover4063 Рік тому

    Please make videos on load runner, Neoload, Dynatrace and appdynamics too

  • @sunilkumarsuman3899
    @sunilkumarsuman3899 Рік тому

    thanks for your video , very useful for me. how can I write response value in csv file. when I execute request then it generates one number as response and I need to use that number in next request as path url (/products/${number}) . please help me.
    Thanks

  • @SanjayPatel-im2sh
    @SanjayPatel-im2sh 3 роки тому

    Good one. But how to write to a particular column in CSV. I want to write PASS or FAIL in Results column of CSV file. Please explain.

  • @udishe
    @udishe 8 місяців тому

    Thank you mam

  • @balagurunathank
    @balagurunathank 2 роки тому

    How to print thread group name in csv file

  • @DevikaKrishnaKumar
    @DevikaKrishnaKumar 3 роки тому +1

    Hi thank you . I am getting the below error when attempting this
    Typed variable declaration : Object constructor .Could you please help

    • @qualityassurancelab7764
      @qualityassurancelab7764  3 роки тому

      Hi, was the file already open when you tried to run the project? And, on which version of JMeter are you working?

  • @subhrajaghsoh1299
    @subhrajaghsoh1299 3 роки тому +1

    I'm running the test with 5 threads, but the result written only once? not for all 5.

    • @qualityassurancelab7764
      @qualityassurancelab7764  3 роки тому

      If you are using the same code as shown in the video for 5 threads, the results would be overridden in the same line. So, you see result written only once.
      After else block, add the code bw.newLine() to move to the next line.

  • @dineshjan20
    @dineshjan20 4 роки тому +1

    Thanks for the video.. In my test plan, I have 9 thread groups.. can we have a single code for collecting the results al together?

    • @qualityassurancelab7764
      @qualityassurancelab7764  4 роки тому

      You are welcome, try by adding the Beanshell Post Processor at Test Plan level.

  • @Gsuresh_3
    @Gsuresh_3 5 місяців тому

    In csv file how add another cell any infor ? From jmeter

  • @anitsengupta3550
    @anitsengupta3550 4 роки тому +2

    Thanks for the video. Just let me know one thing if I want to create multiple xml files in JMeter. How can I write XML tag inside beanshell and how can I generate different XML file for each iteration?

    • @qualityassurancelab7764
      @qualityassurancelab7764  4 роки тому

      You are welcome, to generate XML file, write the java code under BeanShell PostProcessor.
      Firstly, you have to create a Document with DocumentBuilder class, define all the XML content - node, attribute with Element class. In last, use Transformer class to output the entire XML content to stream output, typically a File.
      Please note that if you wish to create different xml file on each iteration, make the use of variables wherever required.

  • @pankajWarthe
    @pankajWarthe 3 роки тому +1

    Thanks for this detailed video. but how can I write specific IDs value which I get in the response to CSV file?

    • @qualityassurancelab7764
      @qualityassurancelab7764  3 роки тому +1

      I believe you would have the Ids in a variable. So, you will pass the variable as bw.write($VariableName)

  • @subhrajaghsoh1299
    @subhrajaghsoh1299 3 роки тому +1

    how can i write, dynamic value extract by regular expression extractor to a csv file?

    • @qualityassurancelab7764
      @qualityassurancelab7764  3 роки тому

      Store the dynamic value in a variable, write that variable in CSV file, instead of hard coded value

  • @mahaboobm4503
    @mahaboobm4503 4 роки тому +1

    Your all sessions are good but I need to suggest one thing plz change jmeter apperence if u don't mind before conducting class,so we can understand easily your methods.

    • @qualityassurancelab7764
      @qualityassurancelab7764  4 роки тому

      Hi, thanks for your time and feedback, Apologies or the inconvenience!
      I will keep this in mind going forward.

  • @pritamdey7531
    @pritamdey7531 4 роки тому

    If we want to execute 5 iterations, how to write 5 iteration result(pass or fail) in a excel in 5 rows one after another?

    • @qualityassurancelab7764
      @qualityassurancelab7764  4 роки тому

      Please follw the steps below:
      Step 1: Add a Logic Controller -> Loop Controller
      Step 2: Provide Loop count as 5
      Step 3: Put the Request and Beanshell post processor under the Loop Controller.
      So, the request will be executed 5 times and it's result will be written to excel file every time using beanshell post processor.

  • @Austin-pw2ud
    @Austin-pw2ud 4 місяці тому

    Add true to line no 4, to override the csv file

  • @rashmiagarwal67
    @rashmiagarwal67 4 роки тому +1

    Hi,
    How to store all the extracted response data variable into CSV file for each iteration (of same request)

    • @qualityassurancelab7764
      @qualityassurancelab7764  4 роки тому +1

      Hi Rashmi, please follow the below steps:
      Step 1: To execute request in iteration, add controller such as Loop controller or For Each controller according to the requirement of iteration
      Step 2: In the script shown in the video, add a line bw.newLine(); after the else block.
      These two steps will make the request to execute in loop and for each loop, data will be written to csv file and will move to next line for next iteration.

    • @sreejithkurup4
      @sreejithkurup4 4 роки тому

      Hi. I have created a time based otp using jsr223 preprocessor. I want to use that otp generated in the next request, where we enter this otp and then login to the application. How can i do that?

  • @priyankakolli5763
    @priyankakolli5763 Рік тому

    Thank you for the amazing tutorial.
    how can i write, multiple dynamic value extract by regular expression extractor and a parameter to a csv file (for 3 fields)?

  • @anil11pal
    @anil11pal 4 роки тому +1

    Thanks for putting this video. when I tried this i encountered the following error.
    ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval In file: inline evaluation of: ``import java.io.*;
    Any inputs on how to pass through this error

    • @qualityassurancelab7764
      @qualityassurancelab7764  4 роки тому +1

      Hi,
      Such errors mostly occur when post processors are not placed at correct position or variables are not defined correctly.
      could you please share the structure of your test plan and the exact script where you get this error?

    • @nileshthummar20
      @nileshthummar20 4 роки тому +1

      @@qualityassurancelab7764 Yes the same issue I was facing, now I realize actually I put single (\) slash at the path of CSV file.

    • @qualityassurancelab7764
      @qualityassurancelab7764  4 роки тому

      @@nileshthummar20 Thanks for sharing. yes, this error is very common and needs precise debugging.
      I find Log Viewer and debug sampler very helpful for debug purpose, hope this video helps you too for debug purpose - ua-cam.com/video/dbCRz2186Vs/v-deo.html

  • @saipavantej
    @saipavantej 4 роки тому +1

    When I run my test plan in non gui mode can't able to write responce to CSV file
    But when I run my test plan in gui mode able to write responce to CSV file
    Can u explain how to write data in CSV file while running Jmeter in non gui mode
    Also I need to overwrite CSV file

    • @qualityassurancelab7764
      @qualityassurancelab7764  4 роки тому +1

      Could you please share the file path of CSV file which you provided in the Beanshell script?

    • @saipavantej
      @saipavantej 4 роки тому

      @@qualityassurancelab7764
      "/home/flyy-dev/apache-jmeter-5.2.1/database/ride_simulator/sidelog.csv"
      Iam using Linux

    • @qualityassurancelab7764
      @qualityassurancelab7764  4 роки тому

      @@saipavantej Could you please try again by providing the complete path starting from Drive(eg. C:\New folder.....csv)

  • @divyalatha6295
    @divyalatha6295 3 роки тому +1

    As I am new to Jmeter,can you Please help me on this scenario
    Step1-send a http request and get response in json-completed this step
    Step2-From above response i have extracted two variables through Json extractor(X_ALL and Y_ALL)-Completed this step
    Step3-In two variables, each variable contains 18 values seperately like below.
    X_ALL=1,2,3,4,5,,7,8,......18
    Y_ALL=a,b,c,d,e,f......18th one
    The below part where i get stuck to implement
    -->1. Get X_All and Y_ALL variables values in array Seperately
    -->2. Iterate 1st value of X_ALL(i.e.,"1") and 1st value of Y_ALL((i.e.,"a")) at a time and store the values in 2 different variables.
    -->3. Pass the stored variables from step2 in next request and get the response
    -->4. From step3, again Extract some variables named Test,Test1
    -->2. Iterate 2nd value of X_ALL(i.e.,"2") and 2nd value of Y_ALL((i.e.,"b")) at a time and store the values in 2 different variables.
    -->3. Pass the stored variables from step2 in next request and get the response
    -->4. From step3, again Extract some variables named Test,Test1
    -->2. Iterate 1st value of X_ALL(i.e.,"3") and 1st value of Y_ALL((i.e.,"c")) at a time and store the values in 2 different variables.
    -->3. Pass the stored variables from step2 in next request and get the response
    -->4. From step3, again Extract some variables named Test,Test1....
    ....
    ....
    ....
    ....
    Likewise continue the same for 18 subaccounts

    • @qualityassurancelab7764
      @qualityassurancelab7764  3 роки тому +1

      Once you fetch multiple values in X_ALL and Y_ALL using JSON Extractor, follow below steps:
      Add 1st for each controller to loop through X_ALL, provide input variable prefix as X_ALL and output Variable name as X. X variable will hold the values present in X_ALL one by one as loop iterates.
      Under 1st for each controller add 2nd for each controller to loop through Y_ALL, provide input variable prefix as Y_ALL and output Variable name as Y. Y variable will hold the values present in Y_ALL one by one as loop iterates.
      Within 2nd For Each controller, add required requests and use the values from X_ALL and Y_ALL as variables ${X} and ${Y}

    • @divyalathamadapuri1754
      @divyalathamadapuri1754 3 роки тому +1

      Tons of thanks for your reply by spending some time!!

  • @pavanmandala8493
    @pavanmandala8493 Рік тому

    You need not create the CSV file explicitly. JMeter will create the csv file

  • @ngocmaile2489
    @ngocmaile2489 Рік тому

    who cares about write to file responseCode or responseMessage? I expected that this session should be written dynamic values for file