Jmeter - Parallel execution of HTTP request after Login - jmeter

Scenario
Navigating to a login page which generates session data key which will be used while entering the credentials for login
Entering credentials along with sessiondataKey(i.e. sessiondatakey is a entered as parameter in Jmeter Http Header )
Login mechanism provides authorization token
Once authorization token is extracted from response ,initialization request is triggered
As this a XHR enabled site - multiple requests are triggered all together at same time to API's once response from initialization service is received (Note - Here in every request authorization token which we got previously is sent as a part of Header)
Question - What should be My Test Plan structure in jmeter where I would like to login with 50 Users (Data referred from CSV datset) - Once Login - Initialization done then fire up all request together.

Just go for Parallel Controller, your test plan should look like:
Login
Parallel Controller
Request 1
Request 2
Request 3
etc.
So Request 1, Request 2, etc. will be executed at the same time, each with its own thread.
See How to Use the Parallel Controller in JMeter article for comprehensive information if needed.
You can install Parallel Controller using JMeter Plugins Manager

Related

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

Form based Authentication- Jmeter

I am testing an API endpoint for which there is a form based authentication(for additional security). Can someone suggest how to handle form based authentication in Jmeter. I tried with HTTP Authorization Manage, still my request is failing.
You basically need to submit a HTML Form by sending a HTTP POST request using JMeter's HTTP Request sampler.
Given you provide correct credentials you should be authorized for further actions.
In some cases you will need to perform correlation as you might have to provide a dynamic parameter (or several) along with the credentials as your application can use these parameters for i.e. CSRF protection or for other reasons so make sure to carefully inspect the request sent by the real browser (you can capture the original request using browser developer tools) and if there are any dynamic parameters - you should extract them from the previous response using a suitable JMeter Post-Processor
Once you successfully log in it should be enough to add HTTP Cookie Manager to maintain the user session.

CSS/JQuery extractor is extracting default value in case of load test, for the random threads

Performing a login and update user test with multiple users.
I have created a CSV file with 200 username and passwords. Running 200 threads
Performing login and update user, with 200 users.
I am extracting the value of csrf token in a variable after the login request. Then, I am passing that csrf variable in the user update, post request.
Running the same request with 100 users, I am able to log in and update the user's details.
Running the same request with 200 users.
getting the connection timeout exception.
Some of the update user post requests are getting failed because csrf variable is extracting the default values of CSS/JQuery extractor. CSRF token actual value is not getting extracted to the variable.
I have also added Authorization, Cookie, Cache and Header Manager in my test plan.
The constant timer is also being used after login request.
I have set the value of timeouts to 120000 in the HTTP request defaults. Even if I am increasing the timeouts, getting the same exception.
Most probably your application under test simply gets overloaded therefore it cannot respond in a timely fashion.
With regards to CSS/JQuery extractor which is failing to get CSRF token - my expectation is that the token is not present in the response for failing samplers.
So I would recommend taking the following troubleshooting steps:
Completely remove Connect and Response timeouts in the HTTP Request Defaults so JMeter will wait for response forever.
Configure JMeter to save responses for failed samplers by adding the next 2 lines to user.properties file:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data.on_error=true
this way you will be able to see how does response look like for failing requests. See Results File Configuration User Manual chapter to learn what other metrics could be useful for your analysis.
Check your application and middleware (web/application/database server/load balancer logs)
Make sure to set up monitoring of baseline OS health metrics on the application under test side. You can do this using JMeter PerfMon Plugin
Just in case double check you're following JMeter Best Practices

JMeter web page test - Your session expired because of inactivity

There will be two actions once we click on log in button
login page action
dashboard action
Part of JMeter
login page action got success.in the continuation
dash board action got failed saying
"text":"Your session expired.","explanation":"Your session expired because of inactivity."
Can anyone help me please..
Your SUT is likely to have some form of verification mechanism which checks user session by verifying parameter(s).
Well-behaved test should do exactly what real browser does, to wit:
Open login page
Perform login
Open dashboard
and your job is to ensure that requests which are being triggered by JMeter are 100% match to the requests which are being sent by the real browser.
Try adding HTTP Cookie Manager to your Test Plan, if your SUT checks the cookie - that should be enough. If not - most probably you will need to perform correlation - the process of extracting dynamic parameters from previous response using JMeter Post-Processors, saving them into JMeter Variables and replacing hard-coded (recorded) values with these variables.

Logout not working in Jmeter script

I have been using JMeter for a while and I am facing a problem in particular related to logout. I am using the below script -
TestPlan
HTTP Cookie Manager
HTTP Request Defaults
ThreadGroup - (scheduled for half and hour)
Once Only Controller
HTTP Request - login
Loop Controller - (forever)
HTTP Request 1
HTTP Request 2
....
HTTP Request 13
tearDown Thread Group
HTTP Request - logout
But the problem here is that even the logout response looks good , the user used for JMeter script login is still actually not logged out. (that i can monitor as as Admin)
Most likely your "Logout" link just clears user's cookies via JavaScript. As per Apache JMeter project main page:
JMeter is not a browser. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever viewed at a time).
So Logout event can be simulated in JMeter by clearing cookies - see "Clear cookies each iteration" box in the HTTP Cookie Manager
NB: Iteration in the HTTP Cookie Manager (as well as in HTTP Cache Manager, etc) is something which is being defined and incremented at Thread Group level, loops triggered by Loop Controller, While Controller, etc. are not considered as "iterations"
It it also possible to clear cookies programatically i.e. from Beanshell Sampler

Resources