How to fetch parent url of the current failing url in jmeter?












0














I am trying to fetch the parent url of the current failing request (for eg consider a travel website ,parent url will be search creteria and current url is selecting flights page).How can we do it .I tried it with putting a if controller after failing url and a beanshell so that it fetches the parent url of all the failings flights request. But what is happening is ,if the current flight request is falining it wont go to the next if controller at all. Execution stops. Can someone guide me with the better way?










share|improve this question



























    0














    I am trying to fetch the parent url of the current failing request (for eg consider a travel website ,parent url will be search creteria and current url is selecting flights page).How can we do it .I tried it with putting a if controller after failing url and a beanshell so that it fetches the parent url of all the failings flights request. But what is happening is ,if the current flight request is falining it wont go to the next if controller at all. Execution stops. Can someone guide me with the better way?










    share|improve this question

























      0












      0








      0







      I am trying to fetch the parent url of the current failing request (for eg consider a travel website ,parent url will be search creteria and current url is selecting flights page).How can we do it .I tried it with putting a if controller after failing url and a beanshell so that it fetches the parent url of all the failings flights request. But what is happening is ,if the current flight request is falining it wont go to the next if controller at all. Execution stops. Can someone guide me with the better way?










      share|improve this question













      I am trying to fetch the parent url of the current failing request (for eg consider a travel website ,parent url will be search creteria and current url is selecting flights page).How can we do it .I tried it with putting a if controller after failing url and a beanshell so that it fetches the parent url of all the failings flights request. But what is happening is ,if the current flight request is falining it wont go to the next if controller at all. Execution stops. Can someone guide me with the better way?







      jmeter jmeter-4.0






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 7:02









      unknownabcd

      122




      122
























          1 Answer
          1






          active

          oldest

          votes


















          0















          1. First of all forget about Beanshell, you should be using JSR223 Test Elements and Groovy language for scripting starting at least from JMeter version 3.1 (for earlier versions it was also recommended, however Groovy engine wasn't included in JMeter distribution)

          2. Add JSR223 PostProcessor as a child of the 2nd request


          3. Put the following code into "Script" area:



            if (!prev.isSuccessful()) {
            log.info('Previous sampler name: ' + ctx.getPreviousSampler().getName())
            log.info('Previous sampler URL: ' + ctx.getPreviousSampler().getUrl().toString())
            }



          4. That's it, you should see the name of the previous sampler and its URL in the Log Viewer panel and in jmeter.log file



            enter image description here



            You can save the URL into a JMeter Variable like:



            vars.put('url', ctx.getPreviousSampler().getUrl().toString())


            once done you will be able to access the value as ${url} where required.




          References:





          • prev stands for current SampleResult


          • ctx is a shorthand for JMeterContext


          • vars is a shorthand for JMeterVariables


          See JavaDoc for the above classes for description of used functions and Apache Groovy - Why and How You Should Use It article for more information on Groovy scripting in JMeter.






          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%2f53294718%2fhow-to-fetch-parent-url-of-the-current-failing-url-in-jmeter%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0















            1. First of all forget about Beanshell, you should be using JSR223 Test Elements and Groovy language for scripting starting at least from JMeter version 3.1 (for earlier versions it was also recommended, however Groovy engine wasn't included in JMeter distribution)

            2. Add JSR223 PostProcessor as a child of the 2nd request


            3. Put the following code into "Script" area:



              if (!prev.isSuccessful()) {
              log.info('Previous sampler name: ' + ctx.getPreviousSampler().getName())
              log.info('Previous sampler URL: ' + ctx.getPreviousSampler().getUrl().toString())
              }



            4. That's it, you should see the name of the previous sampler and its URL in the Log Viewer panel and in jmeter.log file



              enter image description here



              You can save the URL into a JMeter Variable like:



              vars.put('url', ctx.getPreviousSampler().getUrl().toString())


              once done you will be able to access the value as ${url} where required.




            References:





            • prev stands for current SampleResult


            • ctx is a shorthand for JMeterContext


            • vars is a shorthand for JMeterVariables


            See JavaDoc for the above classes for description of used functions and Apache Groovy - Why and How You Should Use It article for more information on Groovy scripting in JMeter.






            share|improve this answer


























              0















              1. First of all forget about Beanshell, you should be using JSR223 Test Elements and Groovy language for scripting starting at least from JMeter version 3.1 (for earlier versions it was also recommended, however Groovy engine wasn't included in JMeter distribution)

              2. Add JSR223 PostProcessor as a child of the 2nd request


              3. Put the following code into "Script" area:



                if (!prev.isSuccessful()) {
                log.info('Previous sampler name: ' + ctx.getPreviousSampler().getName())
                log.info('Previous sampler URL: ' + ctx.getPreviousSampler().getUrl().toString())
                }



              4. That's it, you should see the name of the previous sampler and its URL in the Log Viewer panel and in jmeter.log file



                enter image description here



                You can save the URL into a JMeter Variable like:



                vars.put('url', ctx.getPreviousSampler().getUrl().toString())


                once done you will be able to access the value as ${url} where required.




              References:





              • prev stands for current SampleResult


              • ctx is a shorthand for JMeterContext


              • vars is a shorthand for JMeterVariables


              See JavaDoc for the above classes for description of used functions and Apache Groovy - Why and How You Should Use It article for more information on Groovy scripting in JMeter.






              share|improve this answer
























                0












                0








                0







                1. First of all forget about Beanshell, you should be using JSR223 Test Elements and Groovy language for scripting starting at least from JMeter version 3.1 (for earlier versions it was also recommended, however Groovy engine wasn't included in JMeter distribution)

                2. Add JSR223 PostProcessor as a child of the 2nd request


                3. Put the following code into "Script" area:



                  if (!prev.isSuccessful()) {
                  log.info('Previous sampler name: ' + ctx.getPreviousSampler().getName())
                  log.info('Previous sampler URL: ' + ctx.getPreviousSampler().getUrl().toString())
                  }



                4. That's it, you should see the name of the previous sampler and its URL in the Log Viewer panel and in jmeter.log file



                  enter image description here



                  You can save the URL into a JMeter Variable like:



                  vars.put('url', ctx.getPreviousSampler().getUrl().toString())


                  once done you will be able to access the value as ${url} where required.




                References:





                • prev stands for current SampleResult


                • ctx is a shorthand for JMeterContext


                • vars is a shorthand for JMeterVariables


                See JavaDoc for the above classes for description of used functions and Apache Groovy - Why and How You Should Use It article for more information on Groovy scripting in JMeter.






                share|improve this answer













                1. First of all forget about Beanshell, you should be using JSR223 Test Elements and Groovy language for scripting starting at least from JMeter version 3.1 (for earlier versions it was also recommended, however Groovy engine wasn't included in JMeter distribution)

                2. Add JSR223 PostProcessor as a child of the 2nd request


                3. Put the following code into "Script" area:



                  if (!prev.isSuccessful()) {
                  log.info('Previous sampler name: ' + ctx.getPreviousSampler().getName())
                  log.info('Previous sampler URL: ' + ctx.getPreviousSampler().getUrl().toString())
                  }



                4. That's it, you should see the name of the previous sampler and its URL in the Log Viewer panel and in jmeter.log file



                  enter image description here



                  You can save the URL into a JMeter Variable like:



                  vars.put('url', ctx.getPreviousSampler().getUrl().toString())


                  once done you will be able to access the value as ${url} where required.




                References:





                • prev stands for current SampleResult


                • ctx is a shorthand for JMeterContext


                • vars is a shorthand for JMeterVariables


                See JavaDoc for the above classes for description of used functions and Apache Groovy - Why and How You Should Use It article for more information on Groovy scripting in JMeter.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 14 '18 at 7:53









                Dmitri T

                69.1k33458




                69.1k33458






























                    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%2f53294718%2fhow-to-fetch-parent-url-of-the-current-failing-url-in-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

                    How to pass form data using jquery Ajax to insert data in database?

                    National Museum of Racing and Hall of Fame

                    Guess what letter conforming each word