I added two request one for login to store the session id and another request to check the load test which requires session id.
I made login request as once only, by adding it as a child for once only controller.
But when I test it by adding about 100 or 200 thread the login is also running that much of time. I want to run login request for only starting thread. Is it possible? Below I added my test case hierarchy.
ThreadGroup:
HTTP request default
HTTP cookie manager
once only controller
login HTTP request
HTTP request for number of users
The Once Only Logic Controller tells JMeter to process the controller(s) inside it only once per Thread, and pass over any requests under it during further iterations through the test plan.
Runtime Controller controls the execution of its samplers/requests for the given time. For example, if you have specified Runtime(seconds) to “20”, JMeter will run your test for 20 seconds only.
How Does Throughput Controller Work? What the throughput controller basically does is; control the execution amount for its child requests. For example, in a script where a request is going to be called 100 times in total, it can be reduced up to 50 times with a throughput controller that has a 50% execution parameter.
The "ONLY ONCE" controller doesn't work the way you think it does.
It runs "only once" PER THREAD. Thus, if you have 100 threads, it will run 100 times.
If you want it to run ONCE PER TEST, do the following:
Test Plan (Set thread groups to "run consecutively"
- Cookie Manager
- Thread Group A (1 thread, 1 loop)
- - - Login Logic
- Thread Group B
- - - Rest of test
Please note, if you need to share any variables between threadgroups A and B, you need to set them as properties. Variables cannot be shared between thread groups, but properties can. You'll need to use the properties function for this.
The function __setProperty automatically stores the value as a global variable. The cleanest way to initiate __setProperty would be to create a POST-processor Beanshell script as a child to the sampler that creates the cookie in THREAD A. To retrieve the value in THREAD B, you add the __property function as the VALUE for the parameter that needs the cookie value.
The Beanshell script would look something like this:
props.put("COOKIENAME","COOKIEVALUE"); //creates a property "COOKIENAME" with value "COOKIEVALUE"
print(props.get("COOKIENAME")); //prints the value out to the console
The code above would always have the same value for COOKIENAME, less then idea. So, we need to make sure "COOKIEVALUE" is dynamic. I would recommend putting a POST-PROCESSOR regular expression to extract the cookie value, and then pass that into the beanshell script.
So, our test plan now looks like this:
Test Plan (Set thread groups to "run consecutively"
- Thread Group A (1 thread, 1 loop)
- - - Login Logic
- - - - - Regex to grab cookie, store as "regexCookie"
- - - - - Beanshell to set property
- Thread Group B
- - - Rest of test
And our beanshell script now looks like:
props.put("COOKIENAME",vars.get("regexCookie")); //creates a property "COOKIENAME" with value from "regexCookie"
print(props.get("COOKIENAME")); //prints the value out to the console
Links to the User Manual:
In the new versions of JMeter you can add a "setUp Thread Group" that does exactly what you need.
A special type of ThreadGroup that can be utilized to perform Pre-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 the test proceeds to the executing of regular Thread Groups.
http://jmeter.apache.org/usermanual/component_reference.html#setUp_Thread_Group
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With