Jmeter Viewstates - asp.net

I have j meter setup
TestPlan
ThreadGroup
HTTP CacheManager
HTTP CookieManager
RegularEpression Extractor id="__VIEWSTATE" value="(.+?)"
RegularExpression Extractor id="__EVENTVALIDATION" value="(.+?)"
RecordingController
login ${VIEWSTATE}
browsingForminmyapp.aspx ${VIEWSTATE}
browsingForm2inmyapp.aspx ${VIEWSTATE}
Everything works as expected, but, I would like to set up OnceOnlyController so that my login form gets executed only the number of times as I set Number of threads in my ThreadGroup. If i create this OnceOnly controller, my ViewStates are not getting right and i GET redirrect, object moved, invalid VIEWSTATE.
This would be the setup that is not working, but gets my login form executed right number of times.
TestPlan
ThreadGroup
HTTP CacheManager
HTTP CookieManager
RegularEpression Extractor id="__VIEWSTATE" value="(.+?)"
RegularExpression Extractor id="__EVENTVALIDATION" value="(.+?)"
RecordingController
OnceOnlyController
login.aspx ${VIEWSTATE}
browsingForminmyapp.aspx ${VIEWSTATE}
browsingForm2inmyapp.aspx ${VIEWSTATE}
How can I get it work as it works using first setup, but after creating once only controller things are getting messy, VIEWSTATES are not OK

I would suggest putting your login.aspx sampler under If Controller. Use the following statement as "Condition"
${__BeanShell(vars.getIteration()==1)}
__Beanshell() function - allows executing arbitrary Beanshell script
vars.getIteration() - method which returns current loop number (on thread group level)
Also move your Regular Expression Extractor elements to be children of your login.aspx request elsewise they will be applied to each and every sampler causing additional overhead.

Related

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:
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.

Submit ASP.NET forms in parallel

I need to submit one form multiple times in parallel. The server accepts the parameter _ASYNCPOST.
I can explain in an abstract way how the page works
Login
Submit form search (POST)
POST same form with new data (all these need to be done in parallel)
In the last step, I yield all the requests with every parameter I could find (including __VIEWSTATE, EVENTTARGET, etc)
The problem is that the first post works, but the rest return an error saying "The server data does not match the browser data, hit refresh"
Is what I'm trying to achieve possible?
I followed this doc https://blog.scrapinghub.com/2016/04/20/scrapy-tips-from-the-pros-april-2016-edition/

JMeter: "__VIEWSTATE" and "__EVENTVALIDATION" value does not get replaced after extracting values using Regular Expression Extractor Post Processor

I am trying to load test the ASP.net website and after a bit of research, it became apparent that JMeter was running into issues with VIEWSTATE, which is one of the workarounds ASP.NET WebForms uses to make HTTP appear to be stateful. JMeter is sending a stale value for VIEWSTATE since it is replaying the HTTP requests in the test plan. I extracted the VIEWSTATE from each response and re-include that value on requests. I did it with two Regular Expression Extractors but I still don't see values getting replaced after parameterization.
Your regexp is probably wrong.
It's better to use css/jquery extractor instead of regexp in this case
Just put:
- expression : input[id=__VIEWSTATE]
- attribute : value
and for second one:
expression : input[id=__EVENTVALIDATION]
attribute : value
Use the below regex..it worked for me
input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="([A-Za-z0-9+=/-_]+?)"

EVENTVALIDATION error while scraping asp.net page

I need to get some values from this website. Basically I need to get the Area for every city. I am using Python and beautifulsoup for this. What I am doing is :
First making a Get request to this page and getting __VIEWSTATE AND __EVENTVALIDATION to make a POST request to get cities for a particular state.Till here its working and I am getting cities for every states.
To get Area I need to make another POST with new __VIEWSTATE AND __EVENTVALIDATION and this time i need to send city as well with other parameters.But I am getting error here:
505|error|500|Invalid postback or callback argument. Event validation
is enabled using <pages enableeventvalidation="true"> in configuration
or <%# Page EnableEventValidation="true" %> in a page. For security
purposes, this feature verifies that arguments to postback or callback
events originate from the server control that originally rendered
them. If the data is valid and expected, use the
ClientScriptManager.RegisterForEventValidation method in order to
register the postback or callback data for validation.|</pages>
I have checked each and every argument/parameter in firebug that I need to send to get areas for corresponding cities but no success. Maybe according to me problem is with __VIEWSTATE or __EVENTVALIDATION.
please help me
you have to get and pass the __VIEWSTATE and __EVENTVALIDATION variables in one session call, otherwise when doing the second POST call while reopening connection to the server it expects to receive back already another __VIEWSTATE and __EVENTVALIDATION!
So basically the logics should be as follows:
curl_init()
curl GET __VIEWSTATE and __EVENTVALIDATION
*some logics here *
curl POST parsed out __VIEWSTATE and __EVENTVALIDATION
* some logics here *
curl_close();
Try to add __REQUESTDIGEST form field, it is a validation field used by Sharepoint.
Also, add name of the select element with states as the value of __EVENTTARGET field:
__EVENTTARGET ctl00$ctl25$g_4828177f_5427_4b0f_a968_ad02dc3674ec$ctl01$ddlState
__REQUESTDIGEST 0xDF6A6E14C550004C4A8533A9F5D...,14 Jun 2012 10:13:34 -0000

How to capture submit form response "different domain"?

I have a case where i want to submit a form and get the response from this submit, because based on this response "at least submit complete response" i will make some other logic.
What makes my case is different that this form is on a domain and i am submitting it to another domain name so can't use ajax submit due to cross script security issues.
Anyone face a case like this and have a solution?
I used JQuery code to submit the form:
$('#MyForm').submit();
Form code:
<form target="MyIframe" name="MyForm" id="MyForm"
action="http://mydomain/page.aspx" method="post"> </form>
For cross-domain communication there is no easy client-side way for you to retrieve results. Server-side support would be required - exposing additional services that you can hit on the client (for example by embedding a element into the page).
This allows you to make GET requests to the server and get the result as JSON. One way to do it would be:
Client creates <script src="http://otherdomain.com/gettoken"></script>
This returns something like
var myToken = "ABC123";
This value is inserted into the form, which is then submitted to the same server
The server stores the results of the form under the key of the specified token
Client creates <script src="http://otherdomain.com/getresult?token=ABC123"></script>
Server fetches the form results for ABC123 and returns then as JSON
You need to make the request on the server side...
Dim Response as String
Using Client as New System.Net.WebClient()
Response = Client.UploadData("key=value")
End Using
Then if you want to use AJAX, you will point it to this local handler to bypass the cross-domain issue.

Resources