রবিবার, ২৮ এপ্রিল, ২০১৩

ASP.NET Login testing with jmeter

This is my first technical blog and I am happy to start this at last.

I want to show here how to test login with a ASP.NET website with jmeter, a load-testing tool. The steps are:

Step 1. First Add a Thread Group:
Right click Test Plan and select Add->Thread(Users)->Thread Group.

Since, I am here not concerned with load-testing/performance, that's why I just keep the default number for Number of Threads(user), Ramp-up periods(in seconds) and Loop count. You can rename the thread group name.

Step 2. Add HTTP Request Defaults:
Right Click thread group and select Add->Config Elements->HTTP Request Defaults.
In Server Name or IP, write the name of your website (e.g. www.example.com)


Step 3: Add HTTP Cookie Manager:
This is very important for asp.net login testing, since many things like session variables and others are stored in cookie. Right click thread group and select Add->Config Elements->HTTP Cookie Manager.
Cookie policy should be set to Compatibility.

Step 4:  Add Login page of your test site:

You can add your login page under thread group but I suggest you to add it under a Simple Controller for better grouping. Right click thread group and select Add->Logic Controller->Simple Controller

Then  Right click Simple Controller and select Add->Sampler->HTTP Request.
 In Path, provide the login page's path (here, /Login.aspx), select GET method and rename this controller name as 'Home page' (optional).


Step 5: Provide Login credentials:
Now, Right click Simple Controller again and select Add->Sampler->HTTP Request


Here, the method will be POST, path will be again '/Login.aspx'. Un-check 'Redirect Automatically' and Check 'Follow Redirects'. Now you have to add your login credentials.
1. User Name
2. Password
3. Submit Button

Name of these parameters will be the "name (not the id) of the <input> tag" (look at the example image, it is "ctl00$body$LoginUser$UserName") and value will be userName of the web site.

To find out these exact values of these parameters, you can use the following guidelines
http://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.pdf

You have to add some more parameters here but before that, you need to do something extra. we will come back to this step later.

Step 6: Add Event and ViewState Regular expression extractor:
Right click thread group and select Add->Post Processors->Regular Expression Extractor
Name this as event and regular expression for this:
name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.+?)"


 In same way, add another regular expression extractor and name it viewstate. Regular expression for this:
name="__VIEWSTATE" id="__VIEWSTATE" value="(.+?)"

Step 7: Add event and viewstate values to Login POST page:

Now go back to step 5 and add some these two variables here (event and viewstate) 
1. Name: __VIEWSTATE 
    value: ${VIEWSTATE}
2.  Name: __EVENTVALIDATION
    value: ${EVENTVALIDATION}

Don't forget to click the Encode checkbox.

Step 8: Add View Results Tree:

 The last step is to add View Results Tree from
Add->Listener->View Results Tree

Now save your test plan and click the start button. You can see that the login will be successful inshaAllah.

Your comments are most welcome!

৮টি মন্তব্য:

  1. Thanks a lot for clear explanation :)
    But I don't understand one thing. After running the test, am I supposed to see the logged in page in the response data? because in the response data I still see sign in page but it doesn't look like I signed into my account. Isn't that why we provide username and password so that we can test logging in?

    I am still learning Jmeter. Any help will be greatly appreciated.

    Thank you.

    উত্তরমুছুন
    উত্তরগুলি
    1. Yes, after running the test, you should be able to see the logged in page in the response data for "Login" page in my screenshot. If you don't see it, it means the log in is not successful.

      So, please double check your username/password/event validation/viewstate information.

      Thanks.

      N.B.: Just for a single whitespace in my event validation and viewstate information, my login didn't work. what a surprise. So, please scrutinize very carefully.

      মুছুন
  2. I have followed all steps but it says me "Invalid view state" and because of this error I can not logged in. Please help.

    উত্তরমুছুন
  3. Hello everybody!!

    I am a beginner in JMeter, I want to know if I can make performance testing with JMeter on vb.net applications ??? if so how can I do ???

    Thank you in advance and good day.

    উত্তরমুছুন