Trying to get all the viewstates(count 25) of a sample2 using reg expression(using match no. -1) and debug postprocessor. The previous sample1 has also viewstates(count 10) which i am exracting one by one using reg expression.
The debug postprocessor of sample2 extracting 10 viewstates of sample1 first and then the remaining 15 from sample2. The matchNr count is correct and first 10 values are not from sample2.
How can i make the debug postprocessor to get the viewstates only from sample2?
Debug PostProcessor respects JMeter Scoping Rules so if you want to see JMeter Variables specific only to sample2 - add Debug Post-Processors as a child of the sample2
This way it will be applied only to sample2 and you will see JMeter Variables specific to this sampler.
Related
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
I am trying to print the below code in Beanshell PostProcessor
but i am getting
Code : log.info(ctx.getPreviousResult.getTime());
Error Message: Cannot access field: getPreviousResult
JMeterContext.getPreviousResult() is a function, not field, you need to add parentheses after it
You cannot print a Long value to jmeter.log directly, you need to cast it to String first
There is prev shorthand which stands for parent SampleResult so you can actually shorten your code
Assuming all above amend your code to:
log.info(prev.getTime().toString());
Also be aware that starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language mostly because Groovy has much better performance comparing to Beanshell so consider migrating to JSR223 PostProcessor on next available opportunity, you will not have to change the code.
getPreviousResult is a method so syntax is:
ctx.getPreviousResult().getTime()
So you code should be:
log.info("{}", ctx.getPreviousResult().getTime());
I want to get the max number of loops in the test group. But how?
I do not see anything to do with loops here
JMeterContextService.getContext().getThreadGroup()
Number of loops is not about the Thread Group, it is property of the underlying Loop Controller so you need to amend your code like:
ctx.getThreadGroup().getSamplerController().getProperty('LoopController.loops')
Demo (assumes using __groovy() function):
More information on scripting in JMeter: Apache Groovy - Why and How You Should Use It
You can follow the convention of setting loop count as a property for example using ${__P(loopCount)}. Then get the property number with default in groovy:
props.get("loopCount", "1") as Integer
This is assuming you call JMeter with overriding property, for example:
jmeter -n -t -JloopCount=6 my.jmx
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.
My requirement is i want to use one ThreadGroup and Two CSV data files(data file1 contains lets say 1000 siteurls and datafile two contains 1500 siteurls) i want to stop the jmeter test after hitting 100 and 150 siteurls
Creating two thread groups(1 thread each) and assigning the loop count as 1000 and 1500 is working fine i am able to stop the test after completion of exaclty one iteration of data set
But here i want to implement the same with only one thread group of 5 users how i can achieve this....
Thanks in Adavance..
Use the following code in Beanshell PreProcessor:
import org.apache.commons.io.FileUtils; // necessary import
int lines = FileUtils.readLines(new File("/path/to/csv.file")).size(); // get lines count
vars.put("lines", String.valueOf(lines)); // store the count into "lines" variable
It uses FileUtils.readLines() method to read file contents into set of strings and gets its size and JMeterVariables.put() method to store extracted value into "lines" variable.
You can access lines count as ${lines} where required.
See How to Use BeanShell: JMeter's Favorite Built-in Component guide for more information on Beanshell scripting in JMeter, comprehensive explanation of pre-defined variables and a form of Beanshell cookbook.