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
Related
My test has 2 API requests.
The parameters passed in 2nd API request body are to be unique every time. So I used JSR223 PreProcessor with groovy to generate that using RandomUtils.
The Thread group is set to have 3 threads with 15 sec Ramp up time and used Loop Controller with Loop count as 10. 1st API is in thread group and 2nd API is in Loop Controller as it needs to run multiple times.
But during test execution, for 2nd API one thread is passing same request body with same parameters multiple times. Because of which the test fails. How is that possible?
It's impossible to state "how is that possible" without seeing your Groovy code.
The most common mistake is using JMeter Functions or Variables in Groovy scripts. As per JSR223 Sampler documentation:
The JSR223 test elements have a feature (compilation) that can significantly increase performance. To benefit from this feature:
Use Script files instead of inlining them. This will make JMeter compile them if this feature is available on ScriptEngine and cache them.
Or Use Script Text and check Cache compiled script if available property.
When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.
If this is your case - refactor your code to use vars shorthand for JMeterVariables class instance instead of JMeter Functions or Variables syntax and it should resolve your issue.
We are using for each control to iterate an array based on matchNr count. First time My application is sending all reports call to server together , next time after 10 sec delay again my application sending the same reports calls which are not get completed in first time and so on.
Ex. suppose application is having 10 reports then first time 10 requests goes, then again same request goes by eliminating the completed one (this request count should be less or equal to earlier one)
Note:
Application is having different report count for each users. we can not put fix reports to all users.
Request is same here, only application is adding report name in the body part of the request.
We are trying to simulate chrome behavior with Jmeter during load test.
Array is having the total report count[image1]
request is same only parameter is getting change for each request[image2]
ForEach Controller doesn't execute its children "together"
We are not telepathic enough to guess how does you "array" look like and how exactly you want to "update" it
If you have JMeter Variables in form of:
foo_1=something
foo_2=something else
....
foo_matchNr=number of matches
and want to update the variables with some "new" values there are 2 options:
Set Variables Action sampler (can be installed using JMeter Plugins Manager)
Or any suitable JSR223 Test Element, any of them has vars shorthand for JMeterVariables class instance providing read/write capabilities for JMeter Variables in current thread's 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
I posted this question originally in a much more complicated way, but I've reproduced the issue more simply now so I'm extensively editing my post.
I have a simple Test Plan to exercise an API.
The first thing it does is create a session with a simple HTTP POST. We then extract the session ID from the response using the JSON Path Extractor plugin:
This reads the newly created session's ID into a variable called id_JSON, and subsequent PUT requests use the session ID in their path, i.e. /api/sessions/${id_JSON}/account.
This generally works well, but I have noticed that intermittently, id_JSON will suddenly have the default value NOT_FOUND. Samples will fail and when I look at the request, I can see that it was trying to hit /api/sessions/NOT_FOUND/account instead of a valid ID. What's really confusing me right now is that this will happen after requests have already successfully referenced ${id_JSON} and generated a valid path. It seems like this should be impossible, unless the value of id_JSON was being dynamically checked or looked up repeatedly - otherwise how is it coming up with a different value from one request to the next?
It seems that if any Sample fails, for any reason, subsequent requests in the same thread iteration all fail with id_JSON having the default value NOT_FOUND.
Do I need to declare or manage the variable id_JSON in any special way to ensure that it will get the value of the session ID and retain it throughout the thread iteration, until the next iteration overwrites it with the next session ID?
The Extractor is a Post Processor, meaning it is applied after each sampler. So in you case it will run on the First Get and the 4 Puts.
So what you are noticing is absolutely regular, and if a Sampler fails, the extractor will fail to extract the ID and put NOT_FOUND in value.
If you are sure it does not change, then just put the Post Processor as a child of the first HTTP Request called "Create Session", it will then only run for it and the variable will not change anymore.
You can read more on this at:
http://jmeter.apache.org/usermanual/test_plan.html#scoping_rules
"Go to next loop iteration" operates on Thread Group level.
Using any nested loop controllers doesn't increment global iteration counter. You can test it with either:
${__BeanShell(vars.getIteration();)} function - if you use vanilla JMeter
iterationNum function - if you use JMeter Plugins
So if you move your "looping" on Thread Group level and remove nester Loop Controller(s) (or set their loop count to 1) your approach should work as you expect it to do.
I'm running a set of thread groups (consecutively) and I need to reset a number of parameters at the start of each thread group so that they have a unique value.
Presently I'm referencing a User Paramaters node using a test fragment, and setting the value to value-${__time()}. Unfortunately, this results in the value being used verbatim (without resolving the time).
Is there a better way to achieve per-thread group variables that include function calls?
Works fine for me (Jmeter 2.5.1), as per below example.
Sample params set to ${__time(HMS,)} and value-${__time()} successfully resolved, generated and updated (once per iteration) for each thread (in this case:3 Thread Groups, 5 threads # 3 loops).
Can you please answer why are you using User Parameters via Test Fragment (as per your post)?
...And several articles, just fyi:
Parametrization in JMeter with user parameter
JMeter Variables vs. Properties. vs. Parameters
UPDATED:
Please find below results for example with both User Params and test logic put into Test Fragment and called from Module Controllers.
Works the same way as in sample above: successfully resolved, preserved between samplers in separate loop and updated (once per iteration) between loops for each thread (well, I 've commented in screen the rest of thread groups to get output for the first only; works fine with all TGs enabled too).
I think you could also try to put User Params config from Test Fragment to each thread group and leave in Test Fragment only test logic - if the above schema will still not work for you:
It's not very nice but both the Module Controller and Include Controller are still quite "buggy" and sometimes unpredictable.
You could also try to debug problem controllers in your scenario: select controller > click Help in jmeter's main menu > click Enable Debug > look into jmeter.log for details after execution.
You could also look onto custom Parameterized Controller - maybe it will work better.