我参考了 这个链接,以处理 ASP.net 的典型功能 viewstate。然而,我的要求并不像上面所述那么简单。我正在尝试通过向登录页面发送用户名和密码然后测试其他页面来对我的网站进行负载测试,但只有在登录成功后才允许浏览其他页面。
我为实现此目的采取的步骤如下所示。
- Create Http Proxy Server by selecting WorkBench > Add > Non-Test Elements.
- Changing the network settings in Firefox to the port defined in Http Proxy Server.
- Creating a
Thread Group
by selecting Test Plan > Add > Threads(Users) > Thread Group. - Creating
HTTP Request Defaults
by selecting Thread Group > Add > Config Element > HTTP Request Defaults. - (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
- Create
User Defined Variables
by selecting Thread Group > Add > Config Element > User Defined Variables. 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, twoasp:TextBox
for receiving loginid and password and oneasp:Button
for checking them in db.
The id of them aretxtLogin
,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
I'm adding two Regular Expression Extractor by selecting Thread Group > Add > Post Processors > Regular Expression 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
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
In step 5 I added following data
Send Parameters With the Request: Name: - Value txtLogin - $(login) txtPassword - $(password) __VIEWSTATE - $(viewState) __EVENTVALIDATION - $(eventValidation)
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.
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.
由于我无法确定我缺少哪些要素,因此无法成功使用JMeter。我只更改了这里提到的值,而对于我没有写在这里的所有内容,这些值都是默认类型,如“线程数:”。