How to use JMeter for load testing ASP.net web applications implementing viewstate

瘦欲@ 提交于 2019-12-03 10:17:02

问题


I'm a .net developer having no prior experience in JMeter/Stress testing. I'm trying to load test the ASP.net website that I had developed using JMeter. The reason for using JMeter is that its an open source tool having lots of fame and credibility.
I referred to this link in order to take care of viewstate which is a typical feature of ASP.net. However my requirements are not that simple as stated there. I'm trying to load test my site by sending userid and password to log-in page and then test through other pages which are allowed to be browsed only if log-in is successful.

The steps that I'm taking to achieve this are listed below.

  1. Create Http Proxy Server by selecting WorkBench > Add > Non-Test Elements.
  2. Changing the network settings in Firefox to the port defined in Http Proxy Server.
  3. Creating a Thread Group by selecting Test Plan > Add > Threads(Users) > Thread Group.
  4. Creating HTTP Request Defaults by selecting Thread Group > Add > Config Element > HTTP Request Defaults.
  5. (a) Entering IP for my remote server in Server Name or IP:
    (b) Entering the path to my log-in page as /MyWebApplication/login.aspx
  6. Create User Defined Variables by selecting Thread Group > Add > Config Element > User Defined Variables.
  7. My login.aspx page is very simple, it takes userid and password from two text-boxes and match them in database and if successful, redirects them to LoginSuccess.aspx page.
    My login.aspx has three server controls only, two asp:TextBox for receiving loginid and password and one asp:Button for checking them in db.
    The id of them are txtLogin, txtPassword, btnLogin respectively.

    In User Defined variables (created in step 6), I've added admin and 123admin, which are real logins in db getting checked in login.aspx page and on success is redirecting to LoginSuccess.aspx page.

    User defined variables:

    Name:          Value    Description
    login          admin    
    password       123admin 
    
  8. I'm adding two Regular Expression Extractor by selecting Thread Group > Add > Post Processors > Regular Expression Extractor.

  9. I've renamed the 1st Regular Expression Extractor as View State Extractor and adding following data to them:

    Reference Name: viewstate
    Regular Expression: name="__VIEWSTATE" id="__VIEWSTATE" value="(.+?)"
    Template:$1$
    Match No.(0 for Random): 1
    Default Value: ERROR
    
  10. Similarly I've renamed the 2nd Regular Expression Extractor as Event Validation Extractor and adding following data to them:

    Reference Name: eventValidation
    Regular Expression: name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.+?)"
    Template:$1$
    Match No.(0 for Random): 1
    Default Value: ERROR
    
  11. In step 5 I added following data

    Send Parameters With the Request:
        Name:             - Value
        txtLogin          - $(login)
        txtPassword       - $(password)
        __VIEWSTATE       - $(viewState)
        __EVENTVALIDATION - $(eventValidation)
    
  12. Now I added HTTP Cookie Manager by selecting Thread Group > Add > Config Element > HTTP Cookie Manager.

  13. Now I added Recording Controller by selecting Thread Group > Add > Logic Controller > Recording Controller.

  14. I started HTTP Proxy Server and then using firefox entered the complete URL to my login.aspx page, entered admin and 123admin in the two text boxes and pressed the Login button and got redirected successfully on LoginSuccess.aspx. I stopped the HTTP Proxy Server and closed my firefox browser.

Now I've saved the test plan (containing the recorded steps, just 2 steps here, 1 for login.aspx and another for LoginSuccess.aspx) and running the test and viewing the test result in View Result Tree which is returning 500 error from the server.

I'm unable to determine what ingredient I'm missing here because of which I can't successfully use JMeter. I've only changed those values which are mentioned here and for everything that I didn't write here the values are default type like No of thread:.


回答1:


  1. Please add better schema of your script at least.
  2. Well, in step 11 above you have txtLogin = $(login), txtPassword = $(password), ...
    Referring variable value as $(VAR_NAME) is incorrect, ${VAR_NAME} should be used.
    Can you ensure if that only misspelling in your question - or you have the same in the script?
  3. Use e.g. Debug Sampler / Debug PostProcessor (inserted after both RegEx Extractors applied) to check that values for both viewstate and eventValidation were extracted from your request and your regex queries work correctly.
  4. Look into the Request panel of your 2nd HTTP Request sampler in View Result Tree results to ensure that all the defined params (txtLogin, txtPassword, __VIEWSTATE, __EVENTVALIDATION) with correct values are sent along with request.



回答2:


In step 5, change as follows

Name:             - Value
txtLogin          - ${login}
txtPassword       - ${password}
__VIEWSTATE       - ${viewState}
__EVENTVALIDATION - ${eventValidation}

Also verify, regular expression extractor is working as required. I mean check if it is fetching correct values.




回答3:


I used CSS/JQuery Extractor and it worked for me. With regex extractor for view state {viewState} variable was getting passed and got view state corrupt error message.

parameters to be set in CSS/JQuery extractor are :-

Reference Name: viewState

CSS/JQuery Expression: input[id=__VIEWSTATE]

Attribute: value

The steps i followed are :-

  1. First do recording of login process.
  2. Drag the required pages in thread group.
  3. In get request of login page add two CSS/JQuery extractor for view state and event validation each.
  4. In post request of login page add body parameters as follows and run the batch.

    Name: - Value

    txtLogin - ${login}

    txtPassword - ${password}

    __VIEWSTATE - ${viewState}

    __EVENTVALIDATION - ${eventValidation}




回答4:


Http 500 is. A server error code so it is not your script that's is failing what has to be done is a tag in the .aspx to disabled the security I faced this some months ago



来源:https://stackoverflow.com/questions/15248712/how-to-use-jmeter-for-load-testing-asp-net-web-applications-implementing-viewsta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!