The ONLY ONCE controller does not work as you think.
It runs "only once" PER THREAD. That way, if you have 100 threads, it will execute 100 times.
If you want it to run ONCE PER TEST, follow these steps:
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 thread groups A and B, you need to set them as properties. Variables cannot be shared between stream groups, but properties can. To do this, you need to use the property function.
The __setProperty function automatically saves this value as a global variable. The easiest way to initiate __setProperty is to create a Beanshell script POST processor as a child of the sampler that creates the cookie in THREAD A. To get the value in THREAD B, you add the __property function as the VALUE value for the parameter that requires the cookie value.
The Beanshell script will 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 will always have the same meaning for COOKIENAME, which is less than an idea. So, we have to make sure that "COOKIEVALUE" is dynamic. I would recommend placing a POST-PROCESSOR regular expression to retrieve the cookie value and then passing it to 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 this:
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
User Manual Links: