如何使用 JMeter 对实现视图状态的 ASP.net Web 应用程序进行负载测试 [英] How to use JMeter for load testing ASP.net web applications implementing viewstate

查看:16
本文介绍了如何使用 JMeter 对实现视图状态的 ASP.net Web 应用程序进行负载测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名 .net 开发人员,之前没有 JMeter/压力测试经验.我正在尝试对我使用 JMeter 开发的 ASP.net 网站进行负载测试.使用 JMeter 的原因是它是一个具有很高知名度和可信度的开源工具.
我按顺序参考了此链接处理视图状态,这是 ASP.net 的典型特征.然而,我的要求并不像那里所说的那么简单.我正在尝试通过将用户名和密码发送到登录页面来对我的网站进行负载测试,然后通过其他页面进行测试,这些页面只有在登录成功时才允许浏览.

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. 通过选择 WorkBench > 添加 > 非测试元素来创建 Http 代理服务器.
  2. 将 Firefox 中的网络设置更改为 Http 代理服务器中定义的端口.
  3. 通过选择测试计划">添加">线程(用户)">线程组"来创建 线程组.
  4. 通过选择线程组 > 添加 > 配置元素 > HTTP 请求默认值来创建 HTTP 请求默认值.
  5. (a) 在 Server Name or IP:
    中输入我的远程服务器的 IP(b) 输入我的登录页面的路径为 /MyWebApplication/login.aspx
  6. 通过选择线程组">添加">配置元素">用户定义的变量"来创建 用户定义的变量.
  7. 我的 login.aspx 页面非常简单,它从两个文本框中获取用户 ID 和密码并在数据库中匹配它们,如果成功,则将它们重定向到 LoginSuccess.aspx 页面.
    我的 login.aspx 只有三个服务器控件,两个 asp:TextBox 用于接收登录 ID 和密码,一个 asp:Button 用于在数据库中检查它们.
    它们的id分别是txtLogintxtPasswordbtnLogin.

  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.

在用户定义的变量(在第 6 步中创建)中,我添加了 admin 和 123admin,它们是 db 中的真实登录,在 login.aspx 页面中被检查,成功后重定向到 LoginSuccess.aspx 页面.

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.

用户定义的变量:

Name:          Value    Description
login          admin    
password       123admin 

  • 我通过选择线程组 > 添加 > 后处理器 > 正则表达式提取器来添加两个正则表达式提取器.

  • I'm adding two Regular Expression Extractor by selecting Thread Group > Add > Post Processors > Regular Expression Extractor.

    我将第一个正则表达式提取器重命名为 View State Extractor 并向它们添加以下数据:

    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
    

  • 同样,我将第二个正则表达式提取器重命名为 Event Validation Extractor 并向它们添加以下数据:

  • 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
    

  • 在第 5 步中,我添加了以下数据

  • In step 5 I added following data

    Send Parameters With the Request:
        Name:             - Value
        txtLogin          - $(login)
        txtPassword       - $(password)
        __VIEWSTATE       - $(viewState)
        __EVENTVALIDATION - $(eventValidation)
    

  • 现在我通过选择线程组 > 添加 > 配置元素 > HTTP Cookie 管理器来添加 HTTP Cookie 管理器.

  • Now I added HTTP Cookie Manager by selecting Thread Group > Add > Config Element > HTTP Cookie Manager.

    现在我通过选择线程组 > 添加 > 逻辑控制器 > 录音控制器来添加录音控制器.

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

    我启动了 HTTP 代理服务器,然后使用 firefox 将完整的 URL 输入到我的 login.aspx 页面,在两个文本框中输入 admin 和 123admin 并按下登录按钮并在 LoginSuccess.aspx 上成功重定向.我停止了 HTTP 代理服务器并关闭了我的 Firefox 浏览器.

    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.

    现在我已经保存了测试计划(包含记录的步骤,这里只有 2 个步骤,1 个用于 login.aspx,另一个用于 LoginSuccess.aspx)并运行测试并在返回的查看结果树中查看测试结果来自服务器的 500 错误.

    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.

    我无法确定这里缺少什么成分,因此我无法成功使用 JMeter.我只更改了这里提到的那些值,对于我没有在这里写的所有内容,这些值都是默认类型,例如 No of thread:.

    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. 请至少添加更好的脚本架构.
    2. 好吧,在上面的第 11 步中,您有 txtLogin = $(login), txtPassword = $(password), ...
      将变量值引用为 $(VAR_NAME) 不正确,应该使用 ${VAR_NAME}.
      您能否确保这只是您的问题中的拼写错误 - 或者您在脚本中也有相同的拼写?
    3. 使用例如调试采样器/调试后处理器(在两个 RegEx Extractor 应用后插入)以检查 viewstateeventValidation 的值code> 是从您的请求中提取的,您的正则表达式查询可以正常工作.
    4. 在查看结果树结果中查看第二个 HTTP 请求采样器的请求面板,以确保所有定义的参数(txtLogintxtPassword__VIEWSTATE, __EVENTVALIDATION) 与请求一起发送正确的值.
    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.

    这篇关于如何使用 JMeter 对实现视图状态的 ASP.net Web 应用程序进行负载测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆