本文介绍了正则表达式提取器无法在JMeter中获取asp.net Web表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JMeter登录到asp.net Web窗体应用程序.我将登录序列记录到一个* .jmx文件中,现在我正尝试使用正则表达式提取器后处理器提取__VIEWSTATE,__ VIEWSTATEGENERATOR和__EVENTVALIDATION隐藏输入.

在所有3种情况下,JMeter都提取我要提取的变量的名称(例如"$ {viewstate}"),而不是要提取的值.这是当我查看ViewResults树并选择文本"时RequestBody的样子:

ReturnUrl =%2F& __ VIEWSTATEGENERATOR =%24%7Bviewstategenerator%7D& __ EVENTARGUMENT =& __ VIEWSTATE =%24%7Bviewstate%7D& ctl00%24ContentPlaceHolder1%24Login1%24LoginButton.x = 25& ctler%1%24Content MyPassword%21& ctl00%24ContentPlaceHolder1%24Login1%24LoginButton.y = 4& __ LASTFOCUS =& ctl00%24ContentPlaceHolder1%24Login1%24UserName = MyUserName& __ EVENTTARGET =& __ EVENTVALIDATION =%24%7Bpvalidation>

奇怪的是,如果我在ViewResults树中选择"RegExpTester"并测试我的正则表达式,那么它们似乎都可以正常工作.

例如,这是我的__VIEWSTATE提取器的外观:

正则表达式是这段文本:

name="__VIEWSTATE" id="__VIEWSTATE" value="(.+?)"    

当我将该表达式输入RegExp Tester时,它会找到它.其他2个也可以工作:

这是我第一次使用JMeter,我怀疑我在错误的地方放了东西.

这是我的HTTP请求的设置方式:

这是整个项目的外观:

解决方案

您期望这些值来自何处?您缺少一个 GET 请求,该请求将打开登录页面上,您的测试不应从 POST 请求.

一旦执行GET请求,您的正则表达式提取器将捕获viewstate和好友,并且您将能够登录.

还可以考虑将 CSS选择器提取器切换为.

相关的CSS选择器表达式就像input[id=__VIEWSTATE]一样简单,使用value作为属性.类似地,将剩余的动态值相关联.有关需要的更多详细信息,请参见使用JMeter进行ASP.NET登录测试文章.

Using JMeter, I'm attempting to log in to an asp.net web forms application. I recorded the login sequence to a *.jmx file, and now I'm attempting to extract the __VIEWSTATE, __VIEWSTATEGENERATOR and __EVENTVALIDATION hidden inputs using the Regular Expression Extractor post-processor.

In all 3 cases JMeter is extracting the name of the variable that I want to extract into (eg "${viewstate}") instead of the value I want to extract. Here is what the RequestBody looks like when I look at the ViewResults Tree and select "Text":

ReturnUrl=%2F&__VIEWSTATEGENERATOR=%24%7Bviewstategenerator%7D&__EVENTARGUMENT=&__VIEWSTATE=%24%7Bviewstate%7D&ctl00%24ContentPlaceHolder1%24Login1%24LoginButton.x=25&ctl00%24ContentPlaceHolder1%24Login1%24Password=MyPassword%21&ctl00%24ContentPlaceHolder1%24Login1%24LoginButton.y=4&__LASTFOCUS=&ctl00%24ContentPlaceHolder1%24Login1%24UserName=MyUserName&__EVENTTARGET=&__EVENTVALIDATION=%24%7Beventvalidation%7D

Oddly enough, if I select "RegExpTester" in the ViewResults Tree and test my regular expressions, all of them appear to work.

For example, here is what my __VIEWSTATE extractor looks like:

The Regular Expression is this bit of text:

name="__VIEWSTATE" id="__VIEWSTATE" value="(.+?)"    

When I enter that expression into the RegExp Tester it finds it. The other 2 also work:

This is my first time using JMeter, I suspect I've got something in the wrong place.

Here is how my HTTP Request is set up:

Here is how the entire project looks:

解决方案

Where do you expect these values to come from? You're missing one GET request which will open the login page, your test should not start from POST request.

Once you execute GET request - your Regular Expression extractors will capture viewstate and friends and you will be able to log in.

Also consider switching to CSS Selector Extractors as using regular expressions to parse HTML is not the best idea.

The relevant CSS Selector expression would be as simple as input[id=__VIEWSTATE], use value as the attribute. Similarly correlate remaining dynamic values. See ASP.NET Login Testing with JMeter article for more details if needed.

这篇关于正则表达式提取器无法在JMeter中获取asp.net Web表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 13:49