How to maintain session in Jmeter for testing web application? - jmeter

How to maintain session in Jmeter so that each user should login, search tickets and then logout ? and this process kept going until loop completes for all users.
As I am trying to test our web application with multiple users.

Each JMeter Thread (representing a virtual user) executes samplers upside down so if you have 3 samplers for login, search and logout each thread will execute them in that order.
Keep in mind that:
You need to provide different credentials to each thread so they could impersonate different users. The most common way of parametrization is using CSV Data Set Config
It's better to add HTTP Cookie Manager to represent browser cookies.
It may also be required to perform correlation: in majority of cases application expects dynamic parameters which need to be extracted from previous page response and added to the next request. If you fail to do it you may not even be logged in. The most commonly used test element for correlation is Regular Expression Extractor however depending on the nature of the response it may worth be using CSS/JQuery Extractor, XPath Extractor or JSON Path Extractor

Add Cookie manager. Afterwards it depends on the application you will need dynamic values like viewState or eventValidation or similar ones. But first add the manager and get to the next problem :)

Related

Jmeter - Run multi-threaded users simultaneously without affecting the flow

I have a user flow (create base64 header auth > register request > Register > login > sending data) which I want to run simultaneously (100 users).
If I use the Thread Properties as it is, it will run in asynced way.
Examples:
User 3 will try to login with token of user 1, user 40 will register with registration header created for user 24 and so on..
Token for login extracted from base64 process,
another token is extracted from 'register-request' and used as variable in 'registration' header.
I want first user to register with token created in first register-request and login with token created in base64 process, and so on for next users.
Is there a way to do so?
Normally JMeter virtual users store variables in the thread-local storage so given your test plan design is good each thread (virtual user) should use its own header.
Not knowing the details of how your header is generated it's hard to say what's wrong, I would recommend using Debug Sampler and View Results Tree listener combination and double check the header value (and any interim variables) - hopefully you will be able to determine the cause. If not - you will need to share the test plan somewhere somehow.
Other things to consider:
If your application requires Auhtorization header in form of username:password encoded into Base64 you actually don't need to generate the header manually, you can use HTTP Authorization Manager which automatically generates and adds the relevant header to the requests. Check out How to Use HTTP Basic Authentication in JMeter article for more details if needed.
There is __base64Encode() function which you can use for encoding a custom string into Base64, the function can be installed as a part of Custom JMeter Functions bundle using JMeter Plugins Manager

multiply login request in JMeter

I use JMeter to load data using web services. I need to login from JMeter once, then I need to read ids from CSV file and call HTTP request for each id.
My current configuration is as in the attached picture.
The problem is that in this case login is called for each HTTP Request. I want to change it, so it will be called only once at the beginning. What is the best way to do it in JMeter?
Right click on login -> Insert Parent -> Logic Controller -> Once Only Controller:
The Once Only Logic Controller tells JMeter to process the controller(s) inside it only once per Thread, and pass over any requests under it during further iterations through the test plan.
..
For testing that requires a login, consider placing the login request in this controller since each thread only needs to login once to establish a session.

How to Configure Jmeter for after Login process in an Application?

How to Configure Jmeter for after Login process in an Application?
I am able to configure the login request for 100 users from the CSV file with the help of Jmeter's "CSV Data set Config", but after the successful login of all I want to know how to configure the jmeter to go to the "Offers" page of there(100 user) accounts.Means 1 User can login & View his/her "Offer" page.Please Help.
There are two ways to achieve this scenario:
add another HTTP sampler & fill the details like Server IP, Path of Offers URL (you will have already done the same for Login), HTTP Header data etc. and pass correlation parameters from the response of Login if required to view the offers specific to 1 user.
make sure you use right method (GET/POST) in HTTP Sampler.
record the whole scenario (ref: http://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.pdf).
You will still have to do the correlation of parameters (using regular expression extractor or Xpath extractor) wherever required. This entirely depends on the parameters required for the offer page HTTP request.
hope this will help.
You'll need a cookie manager to store the session and cookie for all logged in users.
http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Cookie_Manager

How to login to an email Address using jmeter?

I am testing some api for our product using jmeter. To test the api to verify the user's email address I need to login to the mail account. I have the email and password of a test user. How can I login using an api or any other way in jmeter?
Is it possible at all?
Yes that is possible. You'll have to create a test plan with multiple steps but these depend on the concrete implementation of the login.
First you must identify the following two locations:
The GET request that gets the initial login form (if this is required).
The POST request that posts the login credentials.
If your service has a stateless login form you can even skip the first step.
Otherwise the response of the GET request will contain stuff which needs to be extracted (e.g. the JSESSIONID if you are using JSF) and sent as a parameters in the POST request. You can use the Regular Expression Extractor of JMeter to extract these values and provide them as variables for use in the subsequent requests.
Here is an example screenshot of a HTTP Request element configured to POST login data to the url /common/j_security_check
You might also need to intercept an authentication token from the server response and then pass that into following requests.
Here is a blog entry with a couple of video tutorials on logins with JMeter:
http://community.blazemeter.com/knowledgebase/articles/80479-how-to-use-jmeter-for-login-authentication
You can use jmeter to login,
two ways:
parameterization using csv file(for more users)/user defined variables(UDV)
Login config elements(for single user)
Now that I understand you want to automatically click on a confirmation link from an email using JMeter, here is a blog entry that explains exactly how to do that:
http://blazemeter.com/blog/how-create-jmeter-script-check-email-during-registration-and-grab-confirmation-url
Ophir

Load Testing with JMeter - will it log into my site at load?

I wish to use JMeter to login to my site, run some reports and log out again as a load test.
Is JMeter the best tool for this? I'm concerned it doesn't maintain the browser session between requests.
You can do this very easily in JMeter. You need to create a HTTP Request Sampler (action type needs to be post), then add all the form fields as parameters (username, password etc) and have the path set to the form target. You'll also need to ensure that you have a HTTP cookie manager set to stay logged in. It's even possible to log in as different users, I wrote a blog on it here for full details on how to load test with multiple user logins in JMeter.
Yes you can use jmeter for this. It supports maintaining session across requests and the scenario you want to test is pretty common one.

Resources