API testing using jmeter












1














I am trying to do some API testing in Jmeter.
I was trying to follow this https://octoperf.com/blog/2018/04/23/jmeter-rest-api-testing/ . But I need to get token from cookie.



Can anyone suggest me a solution? Using Jmeter version 5.0



Sorry, if this question was asked previously. But, I could't find a solution.
enter image description here



enter image description here



enter image description hereenter image description here










share|improve this question





























    1














    I am trying to do some API testing in Jmeter.
    I was trying to follow this https://octoperf.com/blog/2018/04/23/jmeter-rest-api-testing/ . But I need to get token from cookie.



    Can anyone suggest me a solution? Using Jmeter version 5.0



    Sorry, if this question was asked previously. But, I could't find a solution.
    enter image description here



    enter image description here



    enter image description hereenter image description here










    share|improve this question



























      1












      1








      1







      I am trying to do some API testing in Jmeter.
      I was trying to follow this https://octoperf.com/blog/2018/04/23/jmeter-rest-api-testing/ . But I need to get token from cookie.



      Can anyone suggest me a solution? Using Jmeter version 5.0



      Sorry, if this question was asked previously. But, I could't find a solution.
      enter image description here



      enter image description here



      enter image description hereenter image description here










      share|improve this question















      I am trying to do some API testing in Jmeter.
      I was trying to follow this https://octoperf.com/blog/2018/04/23/jmeter-rest-api-testing/ . But I need to get token from cookie.



      Can anyone suggest me a solution? Using Jmeter version 5.0



      Sorry, if this question was asked previously. But, I could't find a solution.
      enter image description here



      enter image description here



      enter image description hereenter image description here







      jmeter web-api-testing jmeter-5.0






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 1:53

























      asked Nov 12 '18 at 0:48









      A J

      5261319




      5261319
























          2 Answers
          2






          active

          oldest

          votes


















          1















          1. According to JMeter Best Practices you should always be using the latest version of JMeter so considering migrating to JMeter 5.0 (or whatever latest version is available at JMeter Downloads page) on next available opportunity.



          2. If the value you're looking for comes as a HTTP Cookie - it makes a perfect sense to use HTTP Cookie Manager to get the cookies values





            • add the next line to user.properties file:



              CookieManager.save.cookies=true


            • restart JMeter to pick the property up


            • that's it, now you should have all incoming cookies stored as JMeter Variables with COOKIE_ prefix



              enter image description here










          share|improve this answer





















          • Thank you, But I am not getting any values under Jmeter variables. I have set Jmeter variables TRUE under debug sampler. I have updated the question with screenshots.
            – A J
            Nov 12 '18 at 23:00












          • To be sure we're at the same page: have you added HTTP Cookie Manager to your Test Plan?
            – Dmitri T
            Nov 13 '18 at 5:44










          • Yeah added cookie manager
            – A J
            Nov 13 '18 at 7:09










          • Can you show the response in View Results Tree listener with Response headers tab open showing the value you want to extract?
            – Dmitri T
            Nov 13 '18 at 7:20










          • @ Dmitri T Added.
            – A J
            Nov 19 '18 at 1:53



















          0














          The above link uses JSON extractor to correlate the value. As you rightly noticed, the JSON extractor can be used only on the body of the response and not on the headers (cookies mostly appear in the response headers). For this purpose, we will have to revert to our traditional Regular expression extractor.



          enter image description here



          Select "Field to check" as "Response Headers" and we are good to go. In this case, Regular Expression needs to be utilized for extracting the value and the approach used in the OPs link cannot be leveraged.



          For example, if my response headers are as below,



          enter image description here



          and if I want to capture the NID token which is in line 11 as part of the Set-Cookie parameter, I would use the below Regex.



          enter image description here



          The cookie value is captured and available for utilization. This is visible in the Debug Sampler.



          enter image description here



          For additional information on how to do correlation using regular expression extractor, use this link How to do Correlation



          Hope this helps!






          share|improve this answer





















            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',
            autoActivateHeartbeat: false,
            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%2f53254728%2fapi-testing-using-jmeter%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









            1















            1. According to JMeter Best Practices you should always be using the latest version of JMeter so considering migrating to JMeter 5.0 (or whatever latest version is available at JMeter Downloads page) on next available opportunity.



            2. If the value you're looking for comes as a HTTP Cookie - it makes a perfect sense to use HTTP Cookie Manager to get the cookies values





              • add the next line to user.properties file:



                CookieManager.save.cookies=true


              • restart JMeter to pick the property up


              • that's it, now you should have all incoming cookies stored as JMeter Variables with COOKIE_ prefix



                enter image description here










            share|improve this answer





















            • Thank you, But I am not getting any values under Jmeter variables. I have set Jmeter variables TRUE under debug sampler. I have updated the question with screenshots.
              – A J
              Nov 12 '18 at 23:00












            • To be sure we're at the same page: have you added HTTP Cookie Manager to your Test Plan?
              – Dmitri T
              Nov 13 '18 at 5:44










            • Yeah added cookie manager
              – A J
              Nov 13 '18 at 7:09










            • Can you show the response in View Results Tree listener with Response headers tab open showing the value you want to extract?
              – Dmitri T
              Nov 13 '18 at 7:20










            • @ Dmitri T Added.
              – A J
              Nov 19 '18 at 1:53
















            1















            1. According to JMeter Best Practices you should always be using the latest version of JMeter so considering migrating to JMeter 5.0 (or whatever latest version is available at JMeter Downloads page) on next available opportunity.



            2. If the value you're looking for comes as a HTTP Cookie - it makes a perfect sense to use HTTP Cookie Manager to get the cookies values





              • add the next line to user.properties file:



                CookieManager.save.cookies=true


              • restart JMeter to pick the property up


              • that's it, now you should have all incoming cookies stored as JMeter Variables with COOKIE_ prefix



                enter image description here










            share|improve this answer





















            • Thank you, But I am not getting any values under Jmeter variables. I have set Jmeter variables TRUE under debug sampler. I have updated the question with screenshots.
              – A J
              Nov 12 '18 at 23:00












            • To be sure we're at the same page: have you added HTTP Cookie Manager to your Test Plan?
              – Dmitri T
              Nov 13 '18 at 5:44










            • Yeah added cookie manager
              – A J
              Nov 13 '18 at 7:09










            • Can you show the response in View Results Tree listener with Response headers tab open showing the value you want to extract?
              – Dmitri T
              Nov 13 '18 at 7:20










            • @ Dmitri T Added.
              – A J
              Nov 19 '18 at 1:53














            1












            1








            1







            1. According to JMeter Best Practices you should always be using the latest version of JMeter so considering migrating to JMeter 5.0 (or whatever latest version is available at JMeter Downloads page) on next available opportunity.



            2. If the value you're looking for comes as a HTTP Cookie - it makes a perfect sense to use HTTP Cookie Manager to get the cookies values





              • add the next line to user.properties file:



                CookieManager.save.cookies=true


              • restart JMeter to pick the property up


              • that's it, now you should have all incoming cookies stored as JMeter Variables with COOKIE_ prefix



                enter image description here










            share|improve this answer













            1. According to JMeter Best Practices you should always be using the latest version of JMeter so considering migrating to JMeter 5.0 (or whatever latest version is available at JMeter Downloads page) on next available opportunity.



            2. If the value you're looking for comes as a HTTP Cookie - it makes a perfect sense to use HTTP Cookie Manager to get the cookies values





              • add the next line to user.properties file:



                CookieManager.save.cookies=true


              • restart JMeter to pick the property up


              • that's it, now you should have all incoming cookies stored as JMeter Variables with COOKIE_ prefix



                enter image description here











            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 12 '18 at 6:47









            Dmitri T

            69k33458




            69k33458












            • Thank you, But I am not getting any values under Jmeter variables. I have set Jmeter variables TRUE under debug sampler. I have updated the question with screenshots.
              – A J
              Nov 12 '18 at 23:00












            • To be sure we're at the same page: have you added HTTP Cookie Manager to your Test Plan?
              – Dmitri T
              Nov 13 '18 at 5:44










            • Yeah added cookie manager
              – A J
              Nov 13 '18 at 7:09










            • Can you show the response in View Results Tree listener with Response headers tab open showing the value you want to extract?
              – Dmitri T
              Nov 13 '18 at 7:20










            • @ Dmitri T Added.
              – A J
              Nov 19 '18 at 1:53


















            • Thank you, But I am not getting any values under Jmeter variables. I have set Jmeter variables TRUE under debug sampler. I have updated the question with screenshots.
              – A J
              Nov 12 '18 at 23:00












            • To be sure we're at the same page: have you added HTTP Cookie Manager to your Test Plan?
              – Dmitri T
              Nov 13 '18 at 5:44










            • Yeah added cookie manager
              – A J
              Nov 13 '18 at 7:09










            • Can you show the response in View Results Tree listener with Response headers tab open showing the value you want to extract?
              – Dmitri T
              Nov 13 '18 at 7:20










            • @ Dmitri T Added.
              – A J
              Nov 19 '18 at 1:53
















            Thank you, But I am not getting any values under Jmeter variables. I have set Jmeter variables TRUE under debug sampler. I have updated the question with screenshots.
            – A J
            Nov 12 '18 at 23:00






            Thank you, But I am not getting any values under Jmeter variables. I have set Jmeter variables TRUE under debug sampler. I have updated the question with screenshots.
            – A J
            Nov 12 '18 at 23:00














            To be sure we're at the same page: have you added HTTP Cookie Manager to your Test Plan?
            – Dmitri T
            Nov 13 '18 at 5:44




            To be sure we're at the same page: have you added HTTP Cookie Manager to your Test Plan?
            – Dmitri T
            Nov 13 '18 at 5:44












            Yeah added cookie manager
            – A J
            Nov 13 '18 at 7:09




            Yeah added cookie manager
            – A J
            Nov 13 '18 at 7:09












            Can you show the response in View Results Tree listener with Response headers tab open showing the value you want to extract?
            – Dmitri T
            Nov 13 '18 at 7:20




            Can you show the response in View Results Tree listener with Response headers tab open showing the value you want to extract?
            – Dmitri T
            Nov 13 '18 at 7:20












            @ Dmitri T Added.
            – A J
            Nov 19 '18 at 1:53




            @ Dmitri T Added.
            – A J
            Nov 19 '18 at 1:53













            0














            The above link uses JSON extractor to correlate the value. As you rightly noticed, the JSON extractor can be used only on the body of the response and not on the headers (cookies mostly appear in the response headers). For this purpose, we will have to revert to our traditional Regular expression extractor.



            enter image description here



            Select "Field to check" as "Response Headers" and we are good to go. In this case, Regular Expression needs to be utilized for extracting the value and the approach used in the OPs link cannot be leveraged.



            For example, if my response headers are as below,



            enter image description here



            and if I want to capture the NID token which is in line 11 as part of the Set-Cookie parameter, I would use the below Regex.



            enter image description here



            The cookie value is captured and available for utilization. This is visible in the Debug Sampler.



            enter image description here



            For additional information on how to do correlation using regular expression extractor, use this link How to do Correlation



            Hope this helps!






            share|improve this answer


























              0














              The above link uses JSON extractor to correlate the value. As you rightly noticed, the JSON extractor can be used only on the body of the response and not on the headers (cookies mostly appear in the response headers). For this purpose, we will have to revert to our traditional Regular expression extractor.



              enter image description here



              Select "Field to check" as "Response Headers" and we are good to go. In this case, Regular Expression needs to be utilized for extracting the value and the approach used in the OPs link cannot be leveraged.



              For example, if my response headers are as below,



              enter image description here



              and if I want to capture the NID token which is in line 11 as part of the Set-Cookie parameter, I would use the below Regex.



              enter image description here



              The cookie value is captured and available for utilization. This is visible in the Debug Sampler.



              enter image description here



              For additional information on how to do correlation using regular expression extractor, use this link How to do Correlation



              Hope this helps!






              share|improve this answer
























                0












                0








                0






                The above link uses JSON extractor to correlate the value. As you rightly noticed, the JSON extractor can be used only on the body of the response and not on the headers (cookies mostly appear in the response headers). For this purpose, we will have to revert to our traditional Regular expression extractor.



                enter image description here



                Select "Field to check" as "Response Headers" and we are good to go. In this case, Regular Expression needs to be utilized for extracting the value and the approach used in the OPs link cannot be leveraged.



                For example, if my response headers are as below,



                enter image description here



                and if I want to capture the NID token which is in line 11 as part of the Set-Cookie parameter, I would use the below Regex.



                enter image description here



                The cookie value is captured and available for utilization. This is visible in the Debug Sampler.



                enter image description here



                For additional information on how to do correlation using regular expression extractor, use this link How to do Correlation



                Hope this helps!






                share|improve this answer












                The above link uses JSON extractor to correlate the value. As you rightly noticed, the JSON extractor can be used only on the body of the response and not on the headers (cookies mostly appear in the response headers). For this purpose, we will have to revert to our traditional Regular expression extractor.



                enter image description here



                Select "Field to check" as "Response Headers" and we are good to go. In this case, Regular Expression needs to be utilized for extracting the value and the approach used in the OPs link cannot be leveraged.



                For example, if my response headers are as below,



                enter image description here



                and if I want to capture the NID token which is in line 11 as part of the Set-Cookie parameter, I would use the below Regex.



                enter image description here



                The cookie value is captured and available for utilization. This is visible in the Debug Sampler.



                enter image description here



                For additional information on how to do correlation using regular expression extractor, use this link How to do Correlation



                Hope this helps!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 12 '18 at 4:34









                M Navneet Krishna

                37829




                37829






























                    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%2f53254728%2fapi-testing-using-jmeter%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







                    Popular posts from this blog

                    Full-time equivalent

                    さくらももこ

                    13 indicted, 8 arrested in Calif. drug cartel investigation