Martkos IT Ltd

View Original

JMeter Correlation

When automating the process of test assets there are often dynamic values that need to be handled. Typically, this is termed correlation. Tools such as Loadrunner offer auto-correlation but the native Apache JMeter does not. (Blazemeter fo offer SmartJMX auto-correlation when using their proxy)

Apache JMeter offers numerous processors to extract content. The Boundary Extractor and RegEx Extractor offer a good degree of coverage across many technologies.

Correlation using the Boundary Extractor post processor

Since the boundary extractor works on the response of a sampler first we need to make a request. In this case we will use the HTTP Request Sampler and perform a GET request on martkos-it.co.uk.

Within the contents of the page that is returned, are a number of values for the string “blog-collection-list”.

e.g.

blog-collection-list-d41d8cd98f00b204e9800998ecf8427e-min.css

blog-collection-list-342036262b204974aa269-min.en-US.js

If we want to extract the values “d41d8cd98f00b204e9800998ecf8427e” and “342036262b204974aa269“ we would need to add a boundary extractor as a post processor on the HTTP request sampler.

In this case the values we would use are LB = “blog-collection-list-”, RB = “-” and Match number = “-1”. With these values JMeter will find the string matching the left boundary and then save the value until it reaches the right boundary which is a minus symbol. Since we have supplied a match number of -1 this tell JMeter to save all matches and assign each to it’s own value in an array.

Left Boundary = blog-collection-list-

Right Boundary = -

Match No = -1

We have added a Debug Postprocessor into the Test Plan to enable us to view the full detail of the response. The highlighted lines show that two values were captured and assigned to blogcollectionlist_1 and blogcollectionlist_2. A third variable called blogcollectionlist_matchNr which provides a count of the number of items returned, in this case blogcollectionlist_matchNr=2.

Now that we have these values stored as variables we can use them in the thread group by simply using the name of the value that we need. So, for instance ${blogcollectionlist_1} would give us “d41d8cd98f00b204e9800998ecf8427e” and ${blogcollectionlist_2} would be “342036262b204974aa269“.

Correlation using the Regular Expression Extractor post processor

If we want to extract the values “d41d8cd98f00b204e9800998ecf8427e” and “342036262b204974aa269“ we would need to add a Regular Expression Extractor as a post processor on the HTTP request sampler.

In this case the values we would use are Regular Expression= “blog-collection-list-([a-z0-9]+)”, Template = “$1$” and Match number = “-1”. With these values JMeter will find the string matching the regular expression and then save the value. Since we have supplied a match number of -1 this tell JMeter to save all matches and assign each to it’s own value in an array.

Regular Expression = blog-collection-list-([a-z0-9]+)

Template = $1$

Match No = -1

Again with the Debug Postprocessor this will enable us to see the variables captured.

The highlighted lines show that two values were captured and assigned to blogcollectionlist_1_g1 and blogcollectionlist_2_g1. A third variable called blogcollectionlist_matchNr which provides a count of the number of items returned, in this case blogcollectionlist_matchNr=2.

The g1 signals that the value is assigned to capture group 1.

Now that we have these values stored as variables we can use them in the thread group by simply using the name of the value that we need. So, for instance ${blogcollectionlist_1_g1} would give us “d41d8cd98f00b204e9800998ecf8427e” and ${blogcollectionlist_2_g1} would be “342036262b204974aa269“.

FURTHER READING

Boundary Extractor

Regular Expression Extractor