Search code examples
jmetercorrelationjmeter-plugins

How to correlate different values in a RegEx with multiple matches with JMeter- Correlation Recorder?


I have a problem in JMeter that I can't figure out how to solve.

Situation:

  • I want to load test an ASP.NET-website.
  • bzm - Correlation Recorder used for recording and correlation
  • ScriptResource and WebResource have multiple occurrences

Now I used following RegEx to extract the ScriptResource values: <script src="(.+/ScriptResource.+?)". Then I stored the 3 matched values into 3 different variables. But I can't replace the values in the found order. Example: First Match: stored in : AspNet_ScriptResource Second match stored in: AspNet_ScriptResource_1 Third match stored in: AspNet_ScriptResource_2

The three matches have all different values, can't paste one value into all 3 matches. So I have to write the value from AspNet_ScriptResource into the first match (matchNr=1). AspNet_ScriptResource_1 into second match (matchNr = 2) and AspNet_ScriptResource_2 into third match (matchNr = 3).

But in the Correlation Rules (in the Correlation Recorder) in the "Correlation Replacement" section, there is no option to choose in which matchNr to write.

Correlation Recorder: Correlation Rules

I tried to use a BeanShell Preprocessor with a for-loop but I only found a way to write in the logs, not in the response body.

Is there a way to solve this with the Correlation Recorder plugin? If not, what options do I have to handle such a scenario?

Thanks for your help! :)


Solution

  • You can raise an enhancement request for the bzm - Correlation Recorder via JMeter Plugins support forum or if you're a BlazeMeter customer and need this piece of functionality asap - you can open a support ticket for implementation of the feature.

    Currently it seems that the Correlation Recorder expects you to provide a regular expression either with the unique match or you will have multiple substitutions with the same value.

    With regards to Beanshell approach:

    1. You can substitute response data, but not with the PreProcessor, you need to do this via the PostProcessor using prev.setResponseData() function
    2. Since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting
    3. If you need to change request data, not the response data, you can do this via sampler.getArguments() function