I am running some tests on JMeter. I am testing a web application and its functionality for example login, homepage, product catalogue. So I have a test script and I am using the ultimate thread group for the users. But I would like to run the login request only once or twice on every 100 requests. I know I can use if controller for that and I tried few solutions but did not work. So I would like to know how I can run requests properly?
2 Answers
You're supposed to share your "few solutions", otherwise it sounds like you're asking us to solve your problem.
If you want to run a Sampler 1 time per 100 iterations you can use the following __jexl3() function as the If Controller's condition:
${__jexl3(${__jm__jp@gc - Ultimate Thread Group__idx} % 100 == 0,)}
If you changed the Ultimate Thread Group label from default jp@gc - Ultimate Thread Group - you will need to change it in the function as well.
More information: 6 Tips for JMeter If Controller Usage
P.S. In majority if cases Throughput Controller is much easier to use
- You can use Once Only Controller to run a request only once per thread/user
- You can use Throughput Controller to run requests by the percentage of total execution or count
- You can use Random Controller to randomly pick one item from the child requests
- You can use If Controller with execution count check
${__groovy(vars.get("loginCount").toInteger() <=4 && (new Random()).nextBoolean() )}
You will have to set the loginCount variable for successful logins
int loginCount = vars.get("loginCount").toInteger().next()
vars.put("loginCount", loginCount.toString())
You need to ensure the login request is executed in the first iteration/loop. For the following iterations, you can randomly pick the login request using other appropriate logic controllers.
Also you can combine them to simulate complex combinations.