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, [email protected]
> <mailto:[email protected]> <[email protected] <mailto:[email protected]>>
> 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: [email protected]
>     <mailto:[email protected]>
>     For additional commands, e-mail: [email protected]
>     <mailto:[email protected]>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]

Reply via email to