How to get the result values appended to an CSV file in jmeter(groovy)











up vote
0
down vote

favorite












I am getting a value from HTTP request which I am writing it into a CSV file, each and every time when the program is executed, the new values are overwritten and not appended to the CSV. I would like to append the values instead of overwriting. I am using Regex and XPath extractor to get the values from the HTTP requests and writing it an CSV file.



new File('/Users/ddd/testgui/queueId1.csv').newWriter().withWriter { w -> 
w << vars.get('queueid')
}









share|improve this question




























    up vote
    0
    down vote

    favorite












    I am getting a value from HTTP request which I am writing it into a CSV file, each and every time when the program is executed, the new values are overwritten and not appended to the CSV. I would like to append the values instead of overwriting. I am using Regex and XPath extractor to get the values from the HTTP requests and writing it an CSV file.



    new File('/Users/ddd/testgui/queueId1.csv').newWriter().withWriter { w -> 
    w << vars.get('queueid')
    }









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am getting a value from HTTP request which I am writing it into a CSV file, each and every time when the program is executed, the new values are overwritten and not appended to the CSV. I would like to append the values instead of overwriting. I am using Regex and XPath extractor to get the values from the HTTP requests and writing it an CSV file.



      new File('/Users/ddd/testgui/queueId1.csv').newWriter().withWriter { w -> 
      w << vars.get('queueid')
      }









      share|improve this question















      I am getting a value from HTTP request which I am writing it into a CSV file, each and every time when the program is executed, the new values are overwritten and not appended to the CSV. I would like to append the values instead of overwriting. I am using Regex and XPath extractor to get the values from the HTTP requests and writing it an CSV file.



      new File('/Users/ddd/testgui/queueId1.csv').newWriter().withWriter { w -> 
      w << vars.get('queueid')
      }






      groovy jmeter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 19:41









      cfrick

      18k13452




      18k13452










      asked Nov 9 at 19:32









      Diya

      53




      53
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          So this works for me, on groovysh 2.5.3 :



          new File('/Users/ddd/testgui/queueId1.csv').newWriter(true).withWriter { w -> 
          w << vars.get('queueid')
          }


          The true in the newWriter is for append == true.






          share|improve this answer























          • I have tried this, but it doesn't work.
            – Diya
            Nov 9 at 19:56










          • first answer was incorrect. the correction above was done on a blank-slate docker, and writing a random string instead of vars.get('queueid').
            – John M I Davis
            Nov 9 at 21:32












          • It gets appended in the same line, I want it in the next line. I tried this code with .txt file
            – Diya
            Nov 15 at 16:47












          • Aha the element, you are capturing needs a newline. Change: << vars.get('queueid') to << vars.get('queueid') << 'n'
            – John M I Davis
            Nov 15 at 17:14












          • Thank you so much. Worked :)
            – Diya
            Nov 16 at 19:46


















          up vote
          0
          down vote













          You can do just:



          new File('/Users/ddd/testgui/queueId1.csv') << vars.get('queueid')




          Be aware that your code is going to work fine only when you have 1 thread, if there will be more - you may suffer from a race condition when 2 threads will be simultaneously writing into a file.



          If you're going to execute this code with > 1 virtual user I would rather recommend going for Sample Variables functionality.



          If you add the next line to user.properties file:



          sample_variables=queueid


          and restart JMeter to pick the property up next time you run your test the .jtl results file will have an extra column with queueid variable value for each thread/request.



          If you want to store it into a separate file - go for Flexible File Writer






          share|improve this answer





















          • Thank you for your help @Dmitri T. I tried this, there were some issues with flexible file writer, the values from the regex were displayed thrice in the flexible file writer (NOTE: I have script to get the unique value from the regex as the regex gives values like _g, _g0, _g1 )
            – Diya
            Nov 15 at 14:14











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232205%2fhow-to-get-the-result-values-appended-to-an-csv-file-in-jmetergroovy%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          So this works for me, on groovysh 2.5.3 :



          new File('/Users/ddd/testgui/queueId1.csv').newWriter(true).withWriter { w -> 
          w << vars.get('queueid')
          }


          The true in the newWriter is for append == true.






          share|improve this answer























          • I have tried this, but it doesn't work.
            – Diya
            Nov 9 at 19:56










          • first answer was incorrect. the correction above was done on a blank-slate docker, and writing a random string instead of vars.get('queueid').
            – John M I Davis
            Nov 9 at 21:32












          • It gets appended in the same line, I want it in the next line. I tried this code with .txt file
            – Diya
            Nov 15 at 16:47












          • Aha the element, you are capturing needs a newline. Change: << vars.get('queueid') to << vars.get('queueid') << 'n'
            – John M I Davis
            Nov 15 at 17:14












          • Thank you so much. Worked :)
            – Diya
            Nov 16 at 19:46















          up vote
          0
          down vote



          accepted










          So this works for me, on groovysh 2.5.3 :



          new File('/Users/ddd/testgui/queueId1.csv').newWriter(true).withWriter { w -> 
          w << vars.get('queueid')
          }


          The true in the newWriter is for append == true.






          share|improve this answer























          • I have tried this, but it doesn't work.
            – Diya
            Nov 9 at 19:56










          • first answer was incorrect. the correction above was done on a blank-slate docker, and writing a random string instead of vars.get('queueid').
            – John M I Davis
            Nov 9 at 21:32












          • It gets appended in the same line, I want it in the next line. I tried this code with .txt file
            – Diya
            Nov 15 at 16:47












          • Aha the element, you are capturing needs a newline. Change: << vars.get('queueid') to << vars.get('queueid') << 'n'
            – John M I Davis
            Nov 15 at 17:14












          • Thank you so much. Worked :)
            – Diya
            Nov 16 at 19:46













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          So this works for me, on groovysh 2.5.3 :



          new File('/Users/ddd/testgui/queueId1.csv').newWriter(true).withWriter { w -> 
          w << vars.get('queueid')
          }


          The true in the newWriter is for append == true.






          share|improve this answer














          So this works for me, on groovysh 2.5.3 :



          new File('/Users/ddd/testgui/queueId1.csv').newWriter(true).withWriter { w -> 
          w << vars.get('queueid')
          }


          The true in the newWriter is for append == true.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 9 at 21:30

























          answered Nov 9 at 19:45









          John M I Davis

          993




          993












          • I have tried this, but it doesn't work.
            – Diya
            Nov 9 at 19:56










          • first answer was incorrect. the correction above was done on a blank-slate docker, and writing a random string instead of vars.get('queueid').
            – John M I Davis
            Nov 9 at 21:32












          • It gets appended in the same line, I want it in the next line. I tried this code with .txt file
            – Diya
            Nov 15 at 16:47












          • Aha the element, you are capturing needs a newline. Change: << vars.get('queueid') to << vars.get('queueid') << 'n'
            – John M I Davis
            Nov 15 at 17:14












          • Thank you so much. Worked :)
            – Diya
            Nov 16 at 19:46


















          • I have tried this, but it doesn't work.
            – Diya
            Nov 9 at 19:56










          • first answer was incorrect. the correction above was done on a blank-slate docker, and writing a random string instead of vars.get('queueid').
            – John M I Davis
            Nov 9 at 21:32












          • It gets appended in the same line, I want it in the next line. I tried this code with .txt file
            – Diya
            Nov 15 at 16:47












          • Aha the element, you are capturing needs a newline. Change: << vars.get('queueid') to << vars.get('queueid') << 'n'
            – John M I Davis
            Nov 15 at 17:14












          • Thank you so much. Worked :)
            – Diya
            Nov 16 at 19:46
















          I have tried this, but it doesn't work.
          – Diya
          Nov 9 at 19:56




          I have tried this, but it doesn't work.
          – Diya
          Nov 9 at 19:56












          first answer was incorrect. the correction above was done on a blank-slate docker, and writing a random string instead of vars.get('queueid').
          – John M I Davis
          Nov 9 at 21:32






          first answer was incorrect. the correction above was done on a blank-slate docker, and writing a random string instead of vars.get('queueid').
          – John M I Davis
          Nov 9 at 21:32














          It gets appended in the same line, I want it in the next line. I tried this code with .txt file
          – Diya
          Nov 15 at 16:47






          It gets appended in the same line, I want it in the next line. I tried this code with .txt file
          – Diya
          Nov 15 at 16:47














          Aha the element, you are capturing needs a newline. Change: << vars.get('queueid') to << vars.get('queueid') << 'n'
          – John M I Davis
          Nov 15 at 17:14






          Aha the element, you are capturing needs a newline. Change: << vars.get('queueid') to << vars.get('queueid') << 'n'
          – John M I Davis
          Nov 15 at 17:14














          Thank you so much. Worked :)
          – Diya
          Nov 16 at 19:46




          Thank you so much. Worked :)
          – Diya
          Nov 16 at 19:46












          up vote
          0
          down vote













          You can do just:



          new File('/Users/ddd/testgui/queueId1.csv') << vars.get('queueid')




          Be aware that your code is going to work fine only when you have 1 thread, if there will be more - you may suffer from a race condition when 2 threads will be simultaneously writing into a file.



          If you're going to execute this code with > 1 virtual user I would rather recommend going for Sample Variables functionality.



          If you add the next line to user.properties file:



          sample_variables=queueid


          and restart JMeter to pick the property up next time you run your test the .jtl results file will have an extra column with queueid variable value for each thread/request.



          If you want to store it into a separate file - go for Flexible File Writer






          share|improve this answer





















          • Thank you for your help @Dmitri T. I tried this, there were some issues with flexible file writer, the values from the regex were displayed thrice in the flexible file writer (NOTE: I have script to get the unique value from the regex as the regex gives values like _g, _g0, _g1 )
            – Diya
            Nov 15 at 14:14















          up vote
          0
          down vote













          You can do just:



          new File('/Users/ddd/testgui/queueId1.csv') << vars.get('queueid')




          Be aware that your code is going to work fine only when you have 1 thread, if there will be more - you may suffer from a race condition when 2 threads will be simultaneously writing into a file.



          If you're going to execute this code with > 1 virtual user I would rather recommend going for Sample Variables functionality.



          If you add the next line to user.properties file:



          sample_variables=queueid


          and restart JMeter to pick the property up next time you run your test the .jtl results file will have an extra column with queueid variable value for each thread/request.



          If you want to store it into a separate file - go for Flexible File Writer






          share|improve this answer





















          • Thank you for your help @Dmitri T. I tried this, there were some issues with flexible file writer, the values from the regex were displayed thrice in the flexible file writer (NOTE: I have script to get the unique value from the regex as the regex gives values like _g, _g0, _g1 )
            – Diya
            Nov 15 at 14:14













          up vote
          0
          down vote










          up vote
          0
          down vote









          You can do just:



          new File('/Users/ddd/testgui/queueId1.csv') << vars.get('queueid')




          Be aware that your code is going to work fine only when you have 1 thread, if there will be more - you may suffer from a race condition when 2 threads will be simultaneously writing into a file.



          If you're going to execute this code with > 1 virtual user I would rather recommend going for Sample Variables functionality.



          If you add the next line to user.properties file:



          sample_variables=queueid


          and restart JMeter to pick the property up next time you run your test the .jtl results file will have an extra column with queueid variable value for each thread/request.



          If you want to store it into a separate file - go for Flexible File Writer






          share|improve this answer












          You can do just:



          new File('/Users/ddd/testgui/queueId1.csv') << vars.get('queueid')




          Be aware that your code is going to work fine only when you have 1 thread, if there will be more - you may suffer from a race condition when 2 threads will be simultaneously writing into a file.



          If you're going to execute this code with > 1 virtual user I would rather recommend going for Sample Variables functionality.



          If you add the next line to user.properties file:



          sample_variables=queueid


          and restart JMeter to pick the property up next time you run your test the .jtl results file will have an extra column with queueid variable value for each thread/request.



          If you want to store it into a separate file - go for Flexible File Writer







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 7:16









          Dmitri T

          68.2k33458




          68.2k33458












          • Thank you for your help @Dmitri T. I tried this, there were some issues with flexible file writer, the values from the regex were displayed thrice in the flexible file writer (NOTE: I have script to get the unique value from the regex as the regex gives values like _g, _g0, _g1 )
            – Diya
            Nov 15 at 14:14


















          • Thank you for your help @Dmitri T. I tried this, there were some issues with flexible file writer, the values from the regex were displayed thrice in the flexible file writer (NOTE: I have script to get the unique value from the regex as the regex gives values like _g, _g0, _g1 )
            – Diya
            Nov 15 at 14:14
















          Thank you for your help @Dmitri T. I tried this, there were some issues with flexible file writer, the values from the regex were displayed thrice in the flexible file writer (NOTE: I have script to get the unique value from the regex as the regex gives values like _g, _g0, _g1 )
          – Diya
          Nov 15 at 14:14




          Thank you for your help @Dmitri T. I tried this, there were some issues with flexible file writer, the values from the regex were displayed thrice in the flexible file writer (NOTE: I have script to get the unique value from the regex as the regex gives values like _g, _g0, _g1 )
          – Diya
          Nov 15 at 14:14


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232205%2fhow-to-get-the-result-values-appended-to-an-csv-file-in-jmetergroovy%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini