I have a JMeter test plan with following http request samplers.
- Login
- Call some functionality which needs a logged in user
- Logout
When I execute the test plan with 5 parallel threads, I see that the sampler 2 is called before calling sampler 1 for some threads, which then fails the response assertions.
Is there any way to specify a sequence of samplers to be executed ?
This should ensure that they are executed sequentially :
So let’s start with thread group.
Number of Threads(users) is 5.
So assuming you have the logic work out for your login sampler. Just add additional sampler to it. So right click on that sample
Add > Post Processors > BSF PostProcessor, inside this post processor big script space write${__setProperty(ThreadValue,${__threadNum},)}.This will save the thread number to your property called
ThreadValue. Make sure you select your language asbeanshellin the dropdown list.Then after the login sampler add the if controller. Add this to the condition field
(${JMeterThread.last_sample_ok}==true) && (${__property(ThreadValue,,)} == ${__threadNum})What this means is that -> do only logged in stuff while the actual login is successful and if the login thread matches the thread you’re currently in.
That’s it you do your login stuff only inside the if controller. If you want to be sure that you logout the right user place additional if controller arround it.
Cheers