How to increase int value obtained from previous response - jmeter

I'm using jmeter and I would like to automate below scenario :
(In general I would like to increase value, I already know how to extract value from previous request)
Execute request_1
Extract value1 from request_1 using Regular expression extractor
Increment value1.
Put new value (increased) to the request_2
Any idea how can I achieve it ?

Check out __intSum() function, you can sum an arbitrary number of arbitrary integers via it.
Given you have a JMeter Variable called yourVar where the extracted value lives, the relevant __intSum() function configuration to increment ${yourVar} value by 1 will be something like:
${__intSum(${yourVar},1,yourVar)}
Demo:
If the value you're getting from the Regular Expression Extractor is more than 2 147 483 647 you will need to use __longSum() function instead.
See Apache JMeter Functions - An Introduction guide for more information on JMeter functions concept.

Related

How to generate Random number in Jmeter with prefix and store it into variable

I am using JMeter's Function Helper Dialogue and i found below syntax -
Syntax - ${__Random(12,99,customer-id)}
Result - random values b/w 12 to 99 getting generated, which will get stored in variable "customer-id"
Now Problem is I have to generate value with prefix 'test' (say-test12) and store it in variable 'customer-id'
How to do that ?
I don't see why would you need this because JMeter Variables can be normally concatenated with plain text so if you need test12 just use test${customer-id} statement where required.
However if you really need to generate some static text followed by a random number you could go for __groovy() function configured like:
${__groovy('test' + org.apache.commons.lang3.RandomUtils.nextInt(12\,99),customer-id)}
Demo:
More information:
RandomUtils JavaDoc
Apache Groovy - Why and How You Should Use It

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! :)
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:
You can substitute response data, but not with the PreProcessor, you need to do this via the PostProcessor using prev.setResponseData() function
Since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting
If you need to change request data, not the response data, you can do this via sampler.getArguments() function

JMeter retrieve value of value

I am using jmeter to test ldap.
As part of my test, I want to search for a random uid on each iteration. I did not find a straight forward answer to this. So my idea was to first select a random number 1-200 and saving that number as a variable named uid, that number would correspond to a UDV name.
For example
uid = 2 and 2 = A123456
in my udv list. However when trying to reference this variable in my ldap search filter.I am trying to use
(uid=${${uid}})
in hopes to get the value of the value of uid. However the search results just show this as a string.
<searchfilter>(uid=${${uid}})</searchfilter>
Is there another way to achieve what I am looking for?
Use __V function
${__V(${uid})}
The V (variable) function returns the result of evaluating a variable name expression. This can be used to evaluate nested variable references
${__V(A${N})} - works OK. A${N} becomes A1, and the __V function returns the value of A1
Perhaps the easiest would be going for __RandomFromMultipleVars() function?
Another option is using __V() function, it can combine and evaluate JMeter Variables

Jmeter : random number with beanshell

I want to add 2 kind of parameters to a post request.
From an http request I extract 2 list of variables:
Order_id = input type="hidden" name="(drag.+?)" value="(\d+?)"
Weight_id = class="draggableviews-weight form-select" id=".+?" name="(drag.+?)"
In the Post Request that follows, I need to repost all this variables. I use a BeanShell PreProcessor for this. The first list is no problem, since this get the same value. The second list should get a new random value between -50 and 50. I also want a different random value for each iteration.
How should I do this ?
If I use Random Variabele Config Element I get the same random int for each variabele. I want a different one for each iteration.
enter image description here
I would recommend using ThreadLocalRandom.nextInt() method like
sampler.addArgument(name2, String.valueOf(java.util.concurrent.ThreadLocalRandom.current().nextInt(-50, 51)));
Don't inline JMeter Functions into Beanshell scripts, either pass them via "Parameters" section and refer via Parameters or args shorthands or use appropriate code-based substitutions.
See How to Use BeanShell: JMeter's Favorite Built-in Component guide for more information on Beanshell scripting in JMeter tests.
To retrieve multiple values from single Regular Expression Extractor, we use Templates as follows:
then refer groups as follows:
In the image, you can see that link is Reference Name and there is only match found with the regular expression.
number of matches is : link_matchNr
first group value : link_1_g1
second group value : link_1_g2
Note: The regular expression I tried on is google.com, you can also simulate the same as follows:
Use Random function as follows:
value2 = ${__Random(-50,50)};
log.info("valuee2 " + value2);
Use Random Variable:
then, refer Output Variable in Beanshell Preprocessor as follows:
value2 = vars.get("randomInt");

Generating function value within variable in Jmeter

I want to use the Random function within the variable in Jmeter for example
${demo_variable_g${__Random(1,4,)}}
I am extracting the values for demo_variable using regular expression extractor. I want to generate random number while using the extracted variable value. How do I do that?
The correct function would be:
${__V(demo_variable_g${__Random(1,4,)})}
From the __V() function documentation
For example, if one has variables A1,A2 and N=1:
${A1} - works OK
${A${N}} - does not work (nested variable reference)
${__V(A${N})} - works OK. A${N} becomes A1, and the __V function returns the value of A1
See Here’s What to Do to Combine Multiple JMeter Variables article for explanation and demos

Resources