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

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

Related

How to clear cookies and cache in jmeter after each iteration?

The scenario is- After logging out from application either i have to close the browser or have to clear the cache in order to login with same user again, else browser will not give me login page and it will directly redirect me to post login.
When i am running my script from jmeter, its failing for 2nd iteration as its not able to find out the login page.
what needs to be done in jmeter for handling this scenario? i have added http cache and cookie manager in test plan.
I already tried
1.JSR223 Post Processor- sampler.getCacheManager().clear()
2.BeanShell PostProcessor- import org.apache.jmeter.protocol.http.control.CookieManager;
CookieManager manager = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager").getObjectValue();
manager.clear(); for all 3 requests of Logout transaction.
There is Same user on each iteration setting on Thread Group level.
If you untick it - both HTTP Cookie Manager and HTTP Cache Manager will be cleared when a thread (virtual user) starts new iteration. (only applies to Thread Group's iterations, controllers like Loop, Foreach, While, etc. won't be impacted)
If you want to proceed with scripting and copy-pasting the code without understanding what it's doing for JSR223 Post Processor the relevant code would be:
prev.getCacheManager().clear()
prev.getCookieManager().clear()
but make sure to place it as a child of the last HTTP Request sampler, see JMeter Scoping Rules - The Ultimate Guide article for more information on the impact of placement of JMeter test elements

Jmeter login script

I am using Jmeter for testng load balance of website.I written a script to test the scenario like to make the user to login into the website and able navigate the user to the dashboard where he can see the recent data by consuming the protected calls.Here i am able to pass the user login scenario but the jmeter showing fail errors regarding the protected calls.When i am searching the url thing whcih is given by jmeter i able to understand that teh protected calls need user credentials to consume data but it fails due to absence of user login things.
Here i am able to pass the user login scenario
are you sure? If JMeter reports the HTTP Request sampler as successful it doesn't necessarily mean that the login will be successful, it might be the case your application responds with status code 200 and some error message explaining why the login has failed and JMeter automatically treats HTTP Status Codes below 400 as successful.
Try inspecting request and response details using View Results Tree listener which has HTML and Browser modes and double check that you're able to login.
If yes - you might need to add HTTP Cookie Manager or perform the correlation of the authorization header in the HTTP Header Manager for the "protected calls" or something like this
If no - you will need to amend your script so login will be successful. In order to avoid such situations in future you might want to add Assertions to your test plan to ensure that JMeter is doing what it's supposed to be doing

JMeter : How to run Multiple Samplers under a single Thread group for multiple concurrent users?

I am new to JMeter and trying to learn JMeter by doing performance testing for one of the application in my organization.
I am facing the blow issue with the concurrent execution of a single thread for multiple users.
Base URL: http://xyz.abc.com/app/
Complete URL : http://xyz.abc.com/app/{RandomSesionID}/Account/Login
I've create a Thread with HTTP Requests as show below.
Thread Group
Hit Base URL
It Loads Login URL
Post Credentials and Click Login
Navigate to Landing Page(baseURL/{RandomSessionID}/Main/Home)
Click Logout(It will navigate to BaseURL/{RandomSessionID}/Main/Home)
When I let the thread count to its default value 1, Everything is working fine. However , The moment I set it to more than 1 (with ramp up time to 10sec), below thing happening.
User 2--->
Hit Base URL
Get The Login URL
Post The Credential
It again goes back to Request 2 (Get The Login URL)
and all the steps of the user are getting redirected to the second request irrespective of what I am requesting.
I tried organizing everything into Simple Controllers to see if the sequence will remain for all users but no avail, I am still running into the same issue.
please help me to understand what is going wrong here and how I can resolve these errors to test the application with more concurrency.
EDIT 1
I did a further investigation on this issue from my end and here are the observations I had.
Case 1: When I create two separate JMeter instances and run the same test parallel with different users, The Thread completely successfully without any errors.
Case 2: Wile Running the Thread with 2 users as mentioned above, The second HTTP request for BaseURL:/Home/Main redirecting the request to /Account/Main instead of going to the next step as shown below.
Image 1 :All The HTTPRequests In Order
Image 2 : This Is the Navigation Request For User 1
Image 3 :User 2 Hitting /Home/Main and Getting Redirected To /Account/Login As Response
Image 4 : User 2 Hitting /Home/Main and Got /Home/Main response
Image 5: User 2 Hitting The /Home/Main and Getting Redirected in Response
As you can see in Image 1, Those are the series of requests which I am making through the thread group and these requests are the same for all the users in the thread.
In Image 2, You can see /Home/Main is a Single GET request with a valid /Home/Main response without any issues.
However, In the Subsequent Images 3-5, You could see that the GET /Home/Main-134 making sub-request and 134-0 and 134-1 with 134-0 to GET /Home/Main and 134-1 to GET /Account/Login.
My Observation: I doubt that JMeter is using a single tab/ instance of the browser and hitting those web requests in the same tab where the first request was initiated. Due to which for the second user, it is always redirecting to the Login Page even though the session ID is valid.
To Confirm whether what I observed is correct, I tried replicating the same scenario in the Chrome Browser as mentoined below.
1. Open Chrome broswer and Access the Base URL.
2. Login and Navigate to Home/Main
3. Now In the same Tab, Type BaseURL and It redirected me to the Login page.
4. Now Enter Credentials of User 2 and login and nvaigate to Home/Main.
5. Now I Try accessing the firt User URL by going back by 3-4 tabs.
However, This won't replicate the exact steps as we are using the browser normally whereas in the requests, we are directly hitting the urls with the GET/POST requests.
I am in a fix and unable to understand what I should do to get through this issue.I am not even sure whether it is the issue with the Application or issue with the Jmeter.
Are there any setting in JMeter which will make sure each Thread (user) of the Thread group gets the option to have a dedicated request instead of using the single instance of the browser internally ?
My expectation is that your It again going back to Request 2 statement is wrong.
Each JMeter thread (virtual user) executes Samplers upside down (or according to Logic Controllers)
So most probably your Get The Login URL is being executed by the second user and given the label of the request is the same you cannot distinguish which user is executing which sampler.
You can add i.e. __threadNum() function as the postfix for the request label like:
Hit Base URL user: ${__threadNum}
this way you will get the information regarding which virtual user is executing which request at each moment of time:
Check out Apache JMeter Functions - An Introduction article to learn more about JMeter Functions concept

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.

Why is only my first HTTP request running?

I'm still pretty new to jmeter. I'm using jmeter 2.9.
I have created a thread group with two threads in it. I have set up an HTTP Request Defaults for the thread group. I have created User Parameters to define person IDs that I'm going to be working with in each thread.
I then set up two HTTP requests. One for login, one for retrieve person. For the login one, I created a regular expression extractor to extract the session key that comes back. I then supply the session key as the parameter for the retrieve person request.
I then sniffed the net traffic and started jmeter test. I wanted to make sure the session key was getting passed into the second parameter OK, but it appears to be running on the login twice and then ending. I am getting a 200 return on the HTTP packet and my jmeter test was set to continue regardless.
I believe I followed chapter 5 of the jmeter user manual to set up this test with the addition of parameters, user parameters, and the regex extractor.
Can anyone give me an idea what i might have done so that the second request never runs?
Add "View Results Tree" listener to see what jMeter is actually doing? You should also check jmeter.log to see if there are any exceptions while generating the 2nd request.

Resources