Tom Regan
Tom Regan

Reputation: 3841

Regular Expression Extractor failing in JMeter for asp.net web forms

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:

enter image description here

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:

enter image description here

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:

enter image description here

Here is how the entire project looks:

enter image description here

Upvotes: 0

Views: 775

Answers (1)

Dmitri T
Dmitri T

Reputation: 168092

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.

Upvotes: 1

Related Questions