0
votes

I have a Web socket Single Read sampler as a child of While Controller. This sampler loops for a certain (dynamic) number of times based on other input conditions. I have to extract a value from one of these responses.

If I add a Regular Expression Extractor as a child of the Web socket sampler, it is not able to capture the correct value as the value gets overwritten as the loop progresses.

My current test plan looks like this:

Thread Group
    \_ .. other components
    \_ While loop
    \_Web socket single read sampler
        \_Regular expression Extractor
    \_ .. other components

Is there a way to specify the regular expression extractor to capture value based on the occurrence of some other text in the response body of the Web socket single read sampler?

Thanks in advance!

2

2 Answers

0
votes

I have solved this problem by designing my test plan as follows:

Thread Group
    \_ .. other components
    \_ While controller
        \_ Web socket single read sampler
            \_ Regular expression extractor to save entire response body
        \_ If controller (condition: occurrence of specific text in response body)
            \_ Dummy sampler (pass saved response body)
                \_ Regular expression extractor to save required value 
    \_ .. other components
0
votes

You can add a JSR223 PostProcessor after the Regular Expression Extractor and use the code like:

if (vars.get('your_variable_here').contains('your_value_here')) {
    vars.put('some_specific_response', prev.getResponseDataAsString())
}

where:

see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on JMeter API shortcuts available for the JSR223 Test Elements.

If the JMeter Variable your_variable_here will contain your_value_here text, the PostProcessor will store the whole parent Sampler response data into ${some_specific_response} JMeter Variable