Reputation: 455
I am trying to load test the login functionality for my server. Login form sends the data to the server in $_POST array in the following format.
Array(
[LoginForm] => Array(
[username] => [email protected]
[password] => 123456
[rememberMe] => 0
)
)
The problem I am facing is that how to send these parameters in jmeter. I have tried to send them in a json payload as below.
{"LoginForm":{"username":"[email protected]","password":"123456","rememberMe":"0"}}
and I have sent the username, password and rememberMe parameters in name value pairs in the request but I am unable to login this way.
Also, after authentication the system redirects to another URL. Will jmeter do that automatically so that I can add assertions in the response. Or, will I have to add another HTTP request for that?
Upvotes: 1
Views: 1864
Reputation: 168002
I believe the fastest and the easiest way is to record a JMeter test using built-in HTTP(S) Test Script Recorder - it will capture the traffic between browser and application under test and store it in form of JMeter HTTP Request samplers.
References:
Also consider adding HTTP Cookie Manager and HTTP Cache Manager to your test plan to make your test more realistic.
Upvotes: 0
Reputation: 175
It sounds like you're using PHP on the backend, I believe if you structure your POST parameters in the JMeter HTTP sampler in the format:
LoginForm[username] = [email protected]
LoginForm[password] = 123456
LoginForm[rememberMe] = 0
The backend should be able to read them as an array.
Take a look at the HTML source of the login form using something like Chrome debugging tools and locate the "name" attributes of the form input elements on the login form, those are the parameter names you need to pass in the HTTP sampler, e.g.
<input type="text" name="LoginForm[username]" />
<input type="password" name="LoginForm[password]" />
To answer your second question, there is a flag on the HTTP sampler to follow redirects which means you can apply the assertions to the HTTP POST sampler and it will be looking at the content of the page you are redirected to.
Vikas' comment is also true, you will likely need a Cookie manager added to your test which will automatically save and send cookies in subsequent requests just like a browser would.
Use the View Results Tree listener to see the request and responses to help with debugging your test.
Upvotes: 2