JMeter - different HTTP request for different number of threads in the same thread group - jmeter

I am load-testing a web application. I have recorded 5 different test scenarios using HTTP test script recorder under the same thread group.
I want to run the script with 5 threads, different thread for each request.
For Ex:
5 HTTP Requests in the same Thread Group.
5 Users. Different user for each HTTP request
1st user 1st HTTP request, 2nd user 2nd HTTP request... 5th user 5th HTTP request.
How to implement this. Any help would be much appreciated.

You can use Switch Controller for this and put __intSum() and __threadNum() functions combinatino as the "Switch Value"
This way each user will pick up the relevant Switch Controller's child:
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

Related

How to synchronize 2 requests (samplers) in JMeter

I have test in jmeter that call get oauth token (Token request) and than call rest web service. Problem is that it call Token request to early and when It call web service, it fails becouse token is no longer valid. Can someone help me to fix it in the way, that Token request will be executed few seconds before web service call?
My test config in jmeter
Throughput Controller
Constant Throughput Timer
Normally you shouldn't do anything because each JMeter thread (virtual user) executes Samplers upside down and looking into your test plan I can see that the token request is before the authenticated request so it shouldn't be a problem (unless token life time is below 1 minute)
Whatever.
If you want to introduce a delay between 2 requests there are following options:
Add Flow Control Action Sampler before the 2nd request
Add a relevant JMeter Timer (i.e. Constant Timer) as a child of the 2nd request

How to send some api call sequentially and some api calls parallely for the same user action

How to send some api call sequentially and some api calls parallely for the same user action .
You can make use of Parallel controller
I tried to simulate your scenario in this screenshot below
I added 2 Debug Samplers before Parallel controller and 2 after the controller. On the right hand side if you see Debug Sampler 3 and Debug Sampler 4 started at same time whereas others have a different start time indicating a sequential run.
For sending requests sequentially just add HTTP Request samplers, one per request and each JMeter thread (virtual user) will execute them upside down
For sending requests in parallel put the relevant HTTP Request samplers under the Parallel Controller

How do I pass the Basic Authorization I get from the one-off Setup Thread Group to the main thread group

I have only one user credentials and would like to simulate multiple users. I created a SetUp Thread Group to have HTTP Authorization manager and Beanshell Postprocessor (to carry forward the cookies to the main thread group which has a Beanshell PreProcessor to get this). But the first sampler in the main thread group is failing because the Authorization is not carried forward from Setup Thread group to the main thread. How do I get it to the main thread group?
A Cookie is a Header
Authorization header is not a Cookie
Therefore if you're copying only cookies it doesn't mean that the Authorization header is also copied.
HTTP Authorization Manager obeys JMeter Scoping Rules so if you move it one level up (to be at the same level with Thread Groups) it will be applied to both Thread Groups and generate the proper Authorization header for all the HTTP Request samplers in its scope.
P.S. Using Beanshell is a some form of a performance anti-pattern, since JMeter 3.1 users are advised to use JSR223 Test Elements and Groovy language

Need to handle duplicate session in jmeter scipt

Below is my Jmeter script flow:
-Thread group
- Test Plan
- Login scripts
- Http header manager
- CSRF authorization using css/Jquery extractor
- Dashboard
- Graph Listener.
Problem is: When i run this test plan with 1 user hit, it passes but when i try it with 50 users(more than 1 user) it fails As in our website Multi sessions are not allowed.
Any help would be appreciated !!
Try adding HTTP Cookie Manager to your Test Plan, if your application manages session basing on cookies - it should fix the issue
It might be the case your application uses URL parameter for session management - in that case go for HTTP URL Re-writing Modifier
Inspect your script more carefully as it might be not only one dynamic parameter (CSRF token), there could be more parameters requiring correlation. Record the same scenario 2 times using HTTP(S) Test Script Recorder and compare 2 results scripts. All parameters which are different need to be correlated.

Running Jmeter for Https app with single user for multiple times through Loop controller

Attached is the snapI am trying to run jmeter for single user with value of 10 in loop controller , I first login into the app and then subsequently uses the CSRF token accordingly for future request .The login is always successful and generates CSRF token, But when i try to use CSRF token for future request , I get unauthorized HTTP 401 reponse code , when running with value 10 in loop controller for single user , the same works when i try to run single user with value 1 in loop controller , Any idea how to fix this? (Note :- All this is present in same thread Group)
Well-behaved JMeter test should be able to loop single user without any problem, most likely you have a problem with your test design or mismatch with the application under test behaviour. General recommendation would look like:
First of all switch to iterations on Thread Group level, JMeter configuration elements don't respect iterations originated from elsewhere as "iterations"
Add Debug Sampler and View Results Tree listener to your Test Plan
Run your test with 1 user and 2 loops
Inspect request and response details, identify missing/extra/different parameters and fix them. See How to Debug your Apache JMeter Script for more details on JMeter test troubleshooting techniques.
Blind shot: your test includes login request and the virtual user is already logged in therefore it doesn't require login on 2nd loop. In this case you have 2 options:
Put the logic which needs to be executed only 1 time under Once Only Controller
If you use HTTP Cookie Manager be aware that Clear cookies each iteration works only on Thread Group-level iterations

Resources