Hello,
In the attached jmx file I created an example of how Debug PostProcessor works when set as a parent element to all child Samplers that are contained in the Module controller. This way the user doesn't have to put it as a child in every existing sample in order to debug it. However, when a test is run, Debug PostProcessor is executed before child extractors that are contained in Passed and Failed samplers. What I would like to achieve is that Debug PostProcessor is executed after the last assertion in order to pick all variables from child extractors and to check whether sampler has failed or not, and in case if failed to Debug only those samplers - create Debug subsampler like Debug PostProcessor does. I copied code from "DebugPostProcessor.java" that is contained in "apache-jmeter-5.5-SNAPSHOT_src.zip" file, into JSR223 Listener, but I couldn't achieve to generate Debug subsampler. Could anyone help me how I can solve this? Does it make sense to suggest new element "Debug Listener" which will have all options like Debug PostProcessor, but also could have options to choose whether to debug passed and/or failed ones? --> "Display only: [checkbox] Errors [checkbox] Success" (like we have in all listeners) Regards, Nikola --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
Here is example code you could use in the JSR223 Listener
<https://jmeter.apache.org/usermanual/component_reference.html#JSR223_Listener> , it produces more or less the same output as the Debug PostProcessor: > def subResult = new org.apache.jmeter.samplers.SampleResult() > subResult.setSuccessful(true) > def responseBody = new StringBuilder() > def newline = System.getProperty('line.separator') > > responseBody.append('SamplerProperties:').append(newline) > > sampler.getProperties().each { property -> > > responseBody.append(property.getKey()).append('=').append(property.getValue()).append(newline) > } > > responseBody.append('JMeterVariables:').append(newline) > vars.entrySet().each { var -> > > responseBody.append(var.getKey()).append('=').append(var.getValue()).append(newline) > } > > subResult.setResponseData(responseBody as String, 'UTF-8') > > prev.addSubResult(subResult) In the above code: *prev* - stands for parent SampleReuslt <https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html> *vars* - stands for JMeterVariables <https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html> class instance See Top 8 JMeter Java Classes You Should Be Using with Groovy <https://www.blazemeter.com/blog/top-8-jmeter-java-classes-you-should-be-using-with-groovy> article to learn more about the above and other JMeter API shorthands available for the JSR223 test elements . -- Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
Thank you for trying to help, Glinus. When I put your code in JSR223 Listener, subsampler is not created in each Passed and Failed samplers as it should be. Also, SamplerProperties and JMeterVariables are not sorted in ascending order like it is in Debug PostProcessor. Check an image in the attachment for more details. At least you managed to create a subsampler which is a step forward :) I'm still looking for a complete solution. Here is example code you could use in the JSR223 Listener --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
> subsampler is not created in each Passed and Failed samplers as it should > be it should be created as long as you're smart enough to properly put the listener (hint - JMeter Scoping Rules <https://www.blazemeter.com/blog/jmeter-scoping-rules-the-ultimate-guide/> ) > SamplerProperties and JMeterVariables are not sorted in ascending order I didn't give you the fish, I taught you how to fish. If you're not able to sort an array alphabetically you should rather consider quitting IT and becoming a bartender. This forum doesn't assume that others will write the code for you, if you're looking for this form of services - consider freelancer marketplaces like fiverr <https://www.fiverr.com/> -- Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
Am 25.02.21 um 20:53 schrieb [hidden email]: >> subsampler is not created in each Passed and Failed samplers as it should >> be > it should be created as long as you're smart enough to properly put the > listener (hint - JMeter Scoping Rules > <https://www.blazemeter.com/blog/jmeter-scoping-rules-the-ultimate-guide/> > ) > > >> SamplerProperties and JMeterVariables are not sorted in ascending order > I didn't give you the fish, I taught you how to fish. > > If you're not able to sort an array alphabetically you should rather > consider quitting IT and becoming a bartender. > > This forum doesn't assume that others will write the code for you, if you're > looking for this form of services - consider freelancer marketplaces like > fiverr <https://www.fiverr.com/> That was not called for. This list is open to everyone to ask for help. If you don't want to provide it, fine. You don't have to answer. Remember that everyone has a different background and has different strengths. Many users of JMeter are using it, as they are not forced to do "programming" (even if they do, in my eyes :)) And by the way, the sorting that is done by DebugPostProcessor has been leveled up with the last nightlies and is not a simple "sort the array" (if it is that simple). That said, thanks for helping out in the first place Felix > > > > > > -- > Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
In reply to this post by Nikola Aleksic
Am 25.02.21 um 20:15 schrieb Nikola Aleksic: > > Thank you for trying to help, Glinus. > > When I put your code in JSR223 Listener, subsampler is not created in > each Passed and Failed samplers as it should be. Also, > SamplerProperties and JMeterVariables are not sorted in ascending > order like it is in Debug PostProcessor. Check an image in the > attachment for more details. > > At least you managed to create a subsampler which is a step forward :) > I'm still looking for a complete solution. I haven't understood completely , what you are missing or what you want to achieve. Can you share your test plan and describe, what you want to see in the tree result viewer? I tried to do a simple listener, that logs all samples and their subresults with the variables at the time the listener is called: import org.apache.jorphan.util.AlphaNumericKeyComparator def logSample(result, level=0) { log.info((" " * level) + result + " => " + result.success) result.subResults.each(r -> logSample(r, level + 1)) } def logVars() { def s = new ArrayList(vars.entrySet()) s.sort(AlphaNumericKeyComparator.INSTANCE) log.info(" vars: " + s) } logSample(sampleResult) logVars() Is this logging everything you want? Felix > > On Thu, 25 Feb 2021 at 15:53, [hidden email] > <mailto:[hidden email]> <[hidden email] <mailto:[hidden email]>> > wrote: > > Here is example code you could use in the JSR223 Listener > <https://jmeter.apache.org/usermanual/component_reference.html#JSR223_Listener > <https://jmeter.apache.org/usermanual/component_reference.html#JSR223_Listener>> > > , it produces more or less the same output as the Debug PostProcessor: > > > > def subResult = new org.apache.jmeter.samplers.SampleResult() > > subResult.setSuccessful(true) > > def responseBody = new StringBuilder() > > def newline = System.getProperty('line.separator') > > > > responseBody.append('SamplerProperties:').append(newline) > > > > sampler.getProperties().each { property -> > > > > > responseBody.append(property.getKey()).append('=').append(property.getValue()).append(newline) > > } > > > > responseBody.append('JMeterVariables:').append(newline) > > vars.entrySet().each { var -> > > > > > responseBody.append(var.getKey()).append('=').append(var.getValue()).append(newline) > > } > > > > subResult.setResponseData(responseBody as String, 'UTF-8') > > > > prev.addSubResult(subResult) > > In the above code: > > *prev* - stands for parent SampleReuslt > <https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html > <https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html>> > > *vars* - stands for JMeterVariables > <https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html > <https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html>> > > class instance > > See Top 8 JMeter Java Classes You Should Be Using with Groovy > <https://www.blazemeter.com/blog/top-8-jmeter-java-classes-you-should-be-using-with-groovy > <https://www.blazemeter.com/blog/top-8-jmeter-java-classes-you-should-be-using-with-groovy>> > > article to learn more about the above and other JMeter API shorthands > available for the JSR223 test elements . > > > > -- > Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html > <http://www.jmeter-archive.org/JMeter-User-f512775.html> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > <mailto:[hidden email]> > For additional commands, e-mail: [hidden email] > <mailto:[hidden email]> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] |
In reply to this post by Nikola Aleksic
Am 25.02.21 um 01:23 schrieb Nikola Aleksic: > Hello, > > In the attached jmx file I created an example of how Debug > PostProcessor works when set as a parent element to all child Samplers > that are contained in the Module controller. This way the user doesn't > have to put it as a child in every existing sample in order to debug it. > > However, when a test is run, Debug PostProcessor is executed *before* > child extractors that are contained in Passed and Failed samplers. > What I would like to achieve is that Debug PostProcessor is executed > *after the last assertion* in order to pick all variables from child > extractors and to check whether sampler has failed or not, and in case > if failed to Debug only those samplers - create Debug subsampler like > Debug PostProcessor does. > > I copied code from "DebugPostProcessor.java" that is contained in > "apache-jmeter-5.5-SNAPSHOT_src.zip" file, into JSR223 Listener, but I > couldn't achieve to generate Debug subsampler. > > Could anyone help me how I can solve this? > > Does it make sense to suggest new element "Debug Listener" which will > have all options like Debug PostProcessor, but also could have options > to choose whether to debug passed and/or failed ones? --> "Display > only: [checkbox] Errors [checkbox] Success" (like we have in all > listeners) If it makes sense to you, then open an enhancement issue and maybe someone will add such a listener. Felix > > Regards, > Nikola > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] |
In reply to this post by Felix Schumacher
Am 28.02.21 um 12:02 schrieb Felix Schumacher: > Am 25.02.21 um 20:15 schrieb Nikola Aleksic: >> Thank you for trying to help, Glinus. >> >> When I put your code in JSR223 Listener, subsampler is not created in >> each Passed and Failed samplers as it should be. Also, >> SamplerProperties and JMeterVariables are not sorted in ascending >> order like it is in Debug PostProcessor. Check an image in the >> attachment for more details. >> >> At least you managed to create a subsampler which is a step forward :) >> I'm still looking for a complete solution. > I haven't understood completely , what you are missing or what you want > to achieve. Can you share your test plan and describe, what you want to > see in the tree result viewer? > > I tried to do a simple listener, that logs all samples and their > subresults with the variables at the time the listener is called: > > import org.apache.jorphan.util.AlphaNumericKeyComparator > > def logSample(result, level=0) { > log.info((" " * level) + result + " => " + result.success) > result.subResults.each(r -> logSample(r, level + 1)) > } > > def logVars() { > def s = new ArrayList(vars.entrySet()) > s.sort(AlphaNumericKeyComparator.INSTANCE) > log.info(" vars: " + s) > } > > logSample(sampleResult) > logVars() > > Is this logging everything you want? After re-reading your first mail and integrating the work from glinius, I came up with the following code for the listener: import org.apache.jorphan.util.AlphaNumericKeyComparator import org.apache.jmeter.samplers.SampleResult newline = System.getProperty('line.separator') def sortedList(entries) { def result = new ArrayList(entries) result.sort(AlphaNumericKeyComparator.INSTANCE) return result } def appendEntries(entries, sb) { sortedList(entries).each(entry -> sb.append(entry.key).append('=').append(entry.value).append(newline) ) } if (!prev.successful) { log.info("add debug-samplers: " + sampleResult + " : " + sampleResult.subResults ) def debugResult = new SampleResult() debugResult.successful = true def responseBody = new StringBuilder() responseBody.append('# SamplerProperties:').append(newline) appendEntries(sampler.properties.entrySet(), responseBody) responseBody.append(newline).append('# JMeterVariables:').append(newline) appendEntries(vars.entrySet(), responseBody) debugResult.setResponseData(responseBody as String, 'UTF-8') sampleResult.subResults.each(r -> r.addSubResult(debugResult)) } With this, you get a sub-sampler in each failed sampler. But note, that the listener is called only twice and thus the variables and properties are always the same. The listener will be called once for the "Transaction Controller Failed" (which has "Generate parent sample" enabled and where the sub-results are actually added) and once for "Transaction Controller Main Failed" where no sub-results are added. I think it would be better to change the last line in the listener to sampleResult.addSubResult(debugResult) That way, you get one sub-sample per (the two mentioned above) Controller, but it is more accurate to the state of variables and properties. If you want to have the listener called for each Sampler, you will have to un-check the "Generate parent sample" Felix > > Felix > >> On Thu, 25 Feb 2021 at 15:53, [hidden email] >> <mailto:[hidden email]> <[hidden email] <mailto:[hidden email]>> >> wrote: >> >> Here is example code you could use in the JSR223 Listener >> <https://jmeter.apache.org/usermanual/component_reference.html#JSR223_Listener >> <https://jmeter.apache.org/usermanual/component_reference.html#JSR223_Listener>> >> >> , it produces more or less the same output as the Debug PostProcessor: >> >> >> > def subResult = new org.apache.jmeter.samplers.SampleResult() >> > subResult.setSuccessful(true) >> > def responseBody = new StringBuilder() >> > def newline = System.getProperty('line.separator') >> > >> > responseBody.append('SamplerProperties:').append(newline) >> > >> > sampler.getProperties().each { property -> >> > >> > >> responseBody.append(property.getKey()).append('=').append(property.getValue()).append(newline) >> > } >> > >> > responseBody.append('JMeterVariables:').append(newline) >> > vars.entrySet().each { var -> >> > >> > >> responseBody.append(var.getKey()).append('=').append(var.getValue()).append(newline) >> > } >> > >> > subResult.setResponseData(responseBody as String, 'UTF-8') >> > >> > prev.addSubResult(subResult) >> >> In the above code: >> >> *prev* - stands for parent SampleReuslt >> <https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html >> <https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html>> >> >> *vars* - stands for JMeterVariables >> <https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html >> <https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html>> >> >> class instance >> >> See Top 8 JMeter Java Classes You Should Be Using with Groovy >> <https://www.blazemeter.com/blog/top-8-jmeter-java-classes-you-should-be-using-with-groovy >> <https://www.blazemeter.com/blog/top-8-jmeter-java-classes-you-should-be-using-with-groovy>> >> >> article to learn more about the above and other JMeter API shorthands >> available for the JSR223 test elements . >> >> >> >> -- >> Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html >> <http://www.jmeter-archive.org/JMeter-User-f512775.html> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> <mailto:[hidden email]> >> For additional commands, e-mail: [hidden email] >> <mailto:[hidden email]> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
Hi, First of all sorry for the late reply. Thank you for the answer and provided code, Felix. In the attached test plan I put your code in JSR223Listener, I created Debug post processor with almost complete behavior in JSR223Listener and JSR223 PostProcessor with the combination of DebugPostProcessor.java, Glinius, and your code for the sorting part. If "JSR223 Listener - Debug PostProcessor behavior" is enabled only among all JSR223 elements, it won't work as expected if Generate parent sampler is checked in Transaction controller. As you already said - The listener will be called once for the "Transaction Controller Failed" (which has "Generate parent sample" enabled and where the sub-results are actually added) and once for "Transaction Controller Main Failed" where no sub-results are added. If Generate parent sampler is not checked in Transaction controller, I get almost what I wanted but I have a need in my test plan to have Generate parent sampler checked, which, unfortunately, doesn't work :/ If "JSR223 Listener - Felix's code" is enabled only among all JSR223 elements, with the last line "sampleResult.subResults.each(r -> r.addSubResult(debugResult))" active, the output is desired one, but as you said, "the listener is called only twice and thus the variables and properties are always the same.". Changing the last line to "sampleResult.addSubResult(debugResult)" is "more accurate to the state of variables and properties." Conclusion is that if "Generate parent sample" is checked, it is not possible to get desired output, if not checked, it is possible. I was curious how the same code will work in JSR223 PostProcessor. If "JSR223 PostProcessor - Debug PostProcessor behavior" is enabled only among all JSR223 elements, Debug PostProcessor behavior is reproduced. It works in all cases like Debug PostProcessor itself - puts subsampler in each child Passed and Failed subsampler. If part "if (prev.isSuccessful())" is changed to "if (!prev.isSuccessful())" it won't work - no subsamplers were created. > If it makes sense to you, then open an enhancement issue and maybe someone will add such a listener. Like you said, the listener is called only twice. Since that is the Listener's behavior and it won't work for all possible cases there is no point to open it, I'm afraid. Thank you both of you guys for your time and will to help. I really appreciate it! :) P.S. Latest nightly is required to run the test successfully. Regards, Nikola On Tue, 2 Mar 2021 at 21:49, Felix Schumacher <[hidden email]> wrote:
--------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
Free forum by Nabble | Edit this page |