Jmeter reading input parameters from dynamically appending file - jmeter

Please tell me, is it possible to read data into Jmeter from a dynamically changing file? I have a file with parameters, which will be appended during the test itself. Is it possible to somehow define a global counter that will allow each thread to read its own line every iteration? User Defined Variables are reset every iteration as i understood.
In theory, I can read a specific line using File.readLines().get(counter) in JSR223 Sampler but problem is how to define correctly this counter.

I believe __counter() function is what you're looking for. If you invoke it like ${__counter(FALSE,)} it will return an incremented value each time it will be called.
Example usage:
More information: How to Use a Counter in a JMeter Test

Related

JMeter override timers / reduce timer for certain step in larger scope

I am running a JMeter scenario which has a certain think time applied for the entire scenario.
During one small loop in this scenario, I wish to decrease the think time between each sampler. E.g., if the default scenario think time, for all samplers, is 500ms, I wish to make this one small loop have a think time of only 100ms.
It does not seem like this is possible, but I also don't see any other questions asking this. Does anyone know of a workaround to accomplish what I am trying for?
This line in the JMeter docs suggests that this is not possible:
Note that timers are processed before each sampler in the scope in which they are found; if there are several timers in the same scope, all the timers will be processed before each sampler.
https://jmeter.apache.org/usermanual/component_reference.html#timers
You can do the following:
Declare a JMeter Variable to hold the default think time somewhere in User Defined Variables
In all Constant Timers (or in the one if it's applied to all the Samplers) set it to use the JMeter Variable from the step 1:
Before entering your "small loop" add a JSR223 PostProcessor to the last Sampler and put the following code into "Script" area:
vars.put('think-time', '100')
In the above code vars stands for JMeterVariables class instance, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information if needed.
Before exiting the "small-loop" do the reverse thing and restore the original value of the think time

How to print iteration number in Pepper-Box plain text config?

I want to print iteration number in pepper-box plain text config and i tried Counter config element of jmeter but during execution it is not replacing iteration number. Like if i am using ${counter} so in execution it is printing ${counter}.
I am using counter config element because i need iteration number in some format like 00001,00002,00003 etc.
I also tried to use function like Counter(TRUE,) but it is just replacing first iteration number and not increasing it. Only first iteration number printing in all next iteration.
In Pepper-Box sampler you can only use a limited subset of built-in template functions having different syntax.
You can try doing something like:
{{org.apache.jmeter.threads.JMeterContextService.getContext().getVariables().get("counter")}}
or if you want to share your script with others you can consider implementing a custom function
Check out Apache Kafka - How to Load Test with JMeter article for more information on building a Kakfa test plan using JMeter

Global incrementing field that could used in thread groups in Jmeter

I have a Test which is running for 30 Thread groups and each thread needs a unique variable which will increment and used when the Test is running.I have used a counter in this case which will be used in the API request body.
Now every time I am using the Test I have to manually go and changed the Starting Value and the Number format in the Counter which is lot of manual work since I am using 30 thread groups
My question is Can I use a global variable which will have a way to get a unique number to each thread group which will be used by each API request
I am a beginner for Jmeter so any help will be appreciated.
There's unique number per thread using function ${
__threadNum}
thread number function simply returns the number of the thread currently being executed
Just parameterize it using __P() function like:
Once done you will be able to override the above properties values via -J command-line argument like:
jmeter -JstartingValue=100 -JnumberFormat=00000 -n -t test.jmx
To make the changes permanent you can add the next lines to user.properties file:
startingValue=100
numberFormat=00000
the values which you pass via the command-line will take over the values which are in the user.properties file.
You can also provide default values like:
${__P(startingValue,1)}
so in case if the startingValue property is not set the test will use 1 as the default value.

how to use jmeter functions in loop controller

My test plan is below
!TestPlan
ThreadGroup
LoopController1
Sampler1
BeanShellPostProcessor
Listener
LoopController2
Sampler2
As part of Beanshellpostprocessor, i am putting count value to a variable
props.put("noOfRecords",vars.get("msg_#"));
Now this value i am placing on 2nd loopcontroller as ${__P(noOfRecords,0)}
This setup is failing for iterations where we don't have any records. So the previous "${__P(noOfRecords,0)}" value is considered while running the Loop2.
Is there any other way we can achieve the dynamic loop counter?
You can use variables or properties in the Loop Controller to change the loop count at run time.
If the Property/Variable is set correctly by the Beanshell postprocessor in your test, It should work. That is, you need to set the value to 0 explicitly when there is no record. Otherwise Properties (which are not destroyed until you close JMeter) might use the previous value.

Using JMeter PreProcessor and User Variables logic

I am new to JMeter and it maybe a stupid question but I still find it hard to understand the concept here.
I have a simple test.
Thread Group with a Single thread with loop count of 2
PreProcessor that place two
variables on the vars map
A loop that execute a request twice based
on the PreProcessor parameters
I expected that the preprocessor will initialize the parameter and it will use the same values twice in the request.
It looks like it’s executing the PreProcessor once pair call.
When I switch the PreProcessor with similar User Defined Variables it reuses the same value on every call.
Can anyone explain the logic here?
I am using JMeter 2.11
A PreProcessor is executed each time the HTTP Request is executed so if you have a total of 2 iterations, you should see log twice, you have it 4 times so maybe number of iteration is different than what your write or you have 2 threads.
When you use User Defined Variables, the value is computed once and then reused. Value will be different per thread.
After reading the documentations and with #UBIK LOAD PACK help I used User Variables and it worked
User Variables - are specific to individual threads.
Pre-Processor is attached to a Sampler element (e.g. http request in our case), then it will execute just prior to that sampler element running
So 4 request for different parameters because it runs before every request
User Defined Variables - It is processed at the start of a test, no matter where it is placed. For simplicity, it is suggested that the element is placed only at the start of a Thread Group. This is why I get the same value all the time

Resources