Call function in user parameter definition - jmeter

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.

Related

Jmeter. How to pass a variable generated by each user in thread to second thread users?

Good day, guys!
What I attempting to do is perform a clean logout for all users after test stops running via duration restriction.
In my case, when user logs in, he gets unique session id parameter that makes it impossible to log with same user from different tab/browser/place, so I need to be sure that user is not blocked after my test completes.
Lets say I use 100 users for a test.
My test looks something like:
Login (get session id)
do stuff
do stuff
Logout (terminate session)
It works fine when I use a constant set of loops, but when I run test with duration, for example, 600 seconds, test stops in the middle after time runs out and my users are blocked until their sessions expire by timeout.
I tried to create a second thread which also contains 100 users and only a logout HTTP sampler, passed and used session id variable to it as described in article https://www.blazemeter.com/blog/knit-one-pearl-two-how-use-variables-different-thread-groups but it seems that my second thread receives only a last session id value so it basically logs out 1 user 100 times, but I need to log out 100 users 1 time.
Does anyone now how to store multiple values of a variable and use them in correct order in other threads?
Not a programmer, just a manual tester with some extra responsibilities.
Thank you.
JMeter Variables are local to each thread, JMeter Properties are global for the whole JVM so if you're passing variables between thread groups make sure you add current thread number as a prefix (or postfix) for the generated property, something like:
In the first Thread Group define user-specific property using __setProperty() and __threadNum() functions combination:
${__setProperty(foo_${__threadNum},${YOUR_VARIABLE_HERE})}
In the second Thread Group get user-specific property using __P() and __threadNum() functions combination:
${__P(foo_${__threadNum},)}
Replace foo with the property name of your choice
Replace YOUR_VARIABLE_HERE with the name of the relevant JMeter Variable
Demo:
See Apache JMeter Functions - An Introduction to get familiarized with JMeter Functions concept.

Adding elements at runtime and executing a jmeter test plan

I am trying to build a jmeter testplan, where all the test values are sent from a csv datafile.I want to add assertions(provided in the datafile) to my HTTP Request at runtime and execute the test. The reason behind doing this is to keep the plan flexible according to the number of assertions. In my case, the assertions are getting added at the runtime; however they fail to get executed. May I know what should be done to get the components added and executed in the same flow?
For example: A part of plan looks like:
XYZ
--HTTP Sampler
-- Response Assertion1
-- Response Assertion2
-- JSON Extractor
where XYZ -->keyword based transaction controller(reusable component)
Everytime I have a request of type XYZ, this chunk of components will get executed. In my case, I do not want to place anything such as Assertions, pre/post processors, extractors in the test plan already. I want to generate these components at run time and execute them (as per my test requisites).
Issue: The problem here is that I cant load the components programmatically and execute them in the same flow. The reason being, the compiler does not know beforehand what all components it needs to execute, so it bypasses the newly added components.
So, I need some alternative solution to execute this.
You can add Response Assertion (or multiple) with Pattern to test filled with a variable as ${testAssert1} and set the variable by default as empty, for example
Put in User Defined Variables name testAssert1 with empty value.
Your assertion(s) will pass until you on run time set the variable with a different value, for example using User Parameters Pre Processor.

JMeter - Why is my variable being re-evaluated midway through my test?

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.

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

What is purpose to use setup threadgroup and teardown threagroup in Jmeter? Please explain same with example

What is purpose to use setup threadgroup and teardown threagroup in Jmeter? Please explain same with example.
I know why we use thread groups and also aware of fact that setup is for pre activities like creating user and monitoring purpose but not sure with an incident where can i use it. same with tear down.
It sounds like you have pretty much figured it out already, but let me give you a few examples of when I've used it.
setup:
Get a large data set from a database into a jmeter variable for use during the test.
Get and log the version number from the system under test:s version number.
Run a javascript to set jmeter properties based on more simple input parameters/properties. Lets say you want to configure the selection of target host a simple true/false value, but in your test you need to expand it to different strings, and you dont want to have logic spread out all over your test plan.
teardown:
Never used it, but I guess it is mainly useful for cleaning up your system (e.g. deleting users that were created during the test)
correct me as i'm probably wrong, but a setUp thread cannot be used to store variables for use on the test threads (that i can see). any variables that i use in the setUp are never available. however, i found that if i use a beanshell and convert the variable in the setUp thread to a property like this
${__setProperty(userToken, ${userToken})};
then on each test thread i either use the property directly like:
${__property(userToken)}
or at the top of my thread i convert the property back into a variable like:
vars.put("userToken","${__property(userToken)}")
however, this seems a bit long winded and it would be great if there was a way to set up variables in the setUP to be used on every thread.
A special type of ThreadGroup that can be utilized to perform Pre-Test/ Post-Test Actions.The behavior of these threads is exactly like a normal Thread Group element.
The difference is that these type of threads execute before/after the test has finished executing its regular Thread Groups.enter image description here

Resources