Archive for June, 2014
Recording HTTPS Traffic with JMeter’s Proxy Server & asp.net login
Recording HTTPS Traffic with JMeter’s Proxy Server _ BlazeMeter
JMeter Expert_ Testing performance of web page with Apache JMeter
Jmeter is an open source web performance testing tool.
The easiest way is to use “proxy” to record what you have done in browser, says firefox, and generate the script required.
For testing an asp.net based web application, below are important
- Regular Expression Extractor to get the viewstate and eventvalidation value generated by asp.net (Web Form only; no need for MVC)
- Adding Cookie Manager for storing cookie for asp.net
Regular Expression Extractors
Our first regular expression extractor will grab the page’s VIEWSTATE element and store it in the JMeterviewState
variable. Add a new Regular Expression Extractor in JMeter by:
- Right click on your Thread Group
- Choose Add -> Post Processors -> Regular Expression Extractor
- Configure as follows
- Reference Name:
viewState
- Regular Expression:
name="__VIEWSTATE" id="__VIEWSTATE" value="(.+?)"
- Template:
$1$
- Math No:
1
- Default Value:
ERROR
- Reference Name:
We also need to include a regex extractor that stores the EVENTVALIDATION element in the eventValidation
variable. Again:
- Right click on your Thread Group
- Choose Add -> Post Processors -> Regular Expression Extractor
- Configure as follows
- Reference Name:
eventValidation
- Regular Expression:
name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.+?)"
- Template:
$1$
- Math No:
1
- Default Value:
ERROR
- Reference Name:
Using the Extracted Values
Now that we have populated the viewState
and eventValidation
values, we need to include them when we POST to our application. In my run, this only happened on the login page.
- Select your login page POST in the Test Plan’s Recording Controller
- Set the
__VIEWSTATE
parameter to${viewState}
- Set the
__EVENTVALIDATION
parameter to${eventValidation}
HTTP Cookie Manager
If you run your test plan now, you will see that it is still not working. This is because ASP.NET WebForms uses a cookie to store the login session. We can solve this with JMeter’s “HTTP Cookie Manager”.
- Right click on your Thread Group
- Choose Add -> Config Element -> HTTP Cookie Manager
Finally, run your Test Plan. You should see that your WebForms application returns the correct responses to JMeter’s requests. If not, double check that you are using the viewState
and eventValidation
variables in your login page POST (or any other post, for that matter) and that you have added the Cookie Manager.
Bonus – Parameterize Credentials Across Threads
Application performance for multiple concurrent logins with the same user is probably not a very interesting test case for your system. Luckily, it is extremely easy to parameterize login credentials for JMeter threads with a “CSV Data Set Config” element.
Store Credentials in CSV File
- Create a text file named
credentials.csv
in the same directory as your Test Plan.jmx
file - Populate
credentials.csv
with the login credentials you want to use (mind extra spaces)
login_1,password_1
login_2,password_2
login_3,password_3
Add CSV Data Set Config
- Select your Thread Group
- Choose Add -> Config Element -> CSV Data Set Config
- Configure as follows
- Filename:
credentials.csv
- Variable Names:
username,password
- Filename:
Use Variable Credentials in Login Post
- Select your login page POST in the Test Plan’s Recording Controller
- Configure as follows
- <Your Login Element ID> :
${username}
- <Your Password Element ID> :
${password}
- <Your Login Element ID> :
Now the threads in your Test Plan will cycle through the credentials specified in your CSV.
Acknowledgements
The following articles were extremely helpful in figuring all of this out:
- Technically Works: Load Testing SharePoint (MOSS) Sites with JMeter
- Technically Works: Load Testing ASP.NET Sites with JMeter
- JMeter Tips: Tip #7: How to add cookie support to your Test Plan
- http://www.markschabacker.com/blog/2013/05/10/jmeter_with_webforms_authentication/