Manipulate post body of httpsampler before request - jmeter

I'm testing an Eclipse-RAP application with JMeter.
In RAP the client (javascript-framework in the browser) communicates with the server over a json-based protocol.
A message looks like this:
{"head":{"requestCounter":3,"uiSessionId":"832834"},"operations":[["set","w1",{"bounds": [0,0,1680,893],"cursorLocation":[1262,-1]}]]}
As you see there is a session-ID stored in uiSessionId. I extracted this id using a "Regular Expression Extractor" and stored it in a variable namedUI_SESSION_ID`.
Then i edited the raw "Post Body" of the recorded HTTP-Request:
{"head":{"requestCounter":3,"uiSessionId":"${UI_SESSION_ID}"},"operations":[["set","w1",{"bounds": [0,0,1680,893],"cursorLocation":[1262,-1]}]]}
and it works.
But i have to alter each Post-Body of each HTTP-Request which can be a lot.
After some research i thought using a "BeanShell PreProcessor" would be the right thing, but:
var sampler = ctx.getCurrentSampler();
would give me a HTTPSampler and i did not find any method which allows me to retrieve the post-body, replace the session-id with the variable and set the altered post-body.
JavaDoc: http://jmeter.apache.org/api/org/apache/jmeter/protocol/http/sampler/HTTPSampler.html
Do you know any way i can replace the uiSessionId with the variable without changing every request manually?

You don't have to. The uiSessionId header has been introduced in a milestone version in preparation for multiple browser-tab support in RAP, but it has been replaced by another mechanism that does not use this header parameter anymore.
As of RAP 2.1 RC1, the client now attaches a “connection id” to every POST request in a URL parameter cid. This parameter does not affect load tests, and you don't have to remove it from your recording. Since every jmeter thread gets its own HttpSession, it's not a problem that all threads have the same cid.
One reason for this change was the ability to load test RAP applications without the kind of problems that you've been struggling with.

Related

Facing issues in __eventvalidation and __viewstate in jmeter

i have a scenario, as given below
once the user navigating to planning page and
clicks on a menu,
it will open the lists of recipes in week wise.
if the users wants to add a recipe for a particular, it has an option to click on '+', which will open a popup window which has all the recipe details available.
I have recorded the scenario using JMeter and it has the dynamic values like __VIEWSTATE and ___EVENTVALIDATION etc., and correlated them as well.
But at the 4th step, in the jmeter instead of proper response body and the below message is displayed.
1|#||4|137|pageRedirect||%2fPerfTesting%2fError.aspx%3faspxerrorpath%3d%2fPerfTesting%2ffi-FI%2fDefault%2fKAXXILA%2fPlanning%2fPlanningMenuWeekView.aspx|
Any suggests
Make sure to add HTTP Cookie Manager to your Test Plan
Make sure that your correlation really works, i.e.
associated JMeter Variables are there
they have correct values (like you extracted the dynamic parameter fully)
depending on your application and extra step might be required like URL-encoding the parameter or vice versa
You can use Debug Sampler and View Results Tree listener combination in order to check these variables
Use an external sniffer tool like Wireshark or Fiddler to capture the requests from JMeter and the real browser, the requests must be exactly the same including:
URL
Headers
Request body
all the dynamic parameters must be properly correlated. Given you will send the same request you should get the same response

Can JMeter do automation testing like Selenium can do?

i am still new to JMeter and i was assigned to a work that I will need to use JMeter to perform automation testing. The idea is to write script using JMeter and run the script to fill in the forms in the website. I was curious that can JMeter use different data from the database to fill in the form of the website everytime it execute?(unique data for every user)
I have followed this tutorial (https://www.blazemeter.com/blog/fill-forms-and-submit-with-jmeter-made-easy/ ) and it succeed, however, when i try to change the parameter name (to some other names that do not matches the field name found in the inpect mode), it still works. So i was wondering how JMeter knows where to put in the parameter even i have change to a wrong field name?
As per JMeter Project main page:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
Browsers don't do any magic, they execute HTTP Requests, wait for response and render it. JMeter in its turn can execute the same HTTP requests so traffic would be the same, however it will not render the response, but rather measure the time and collect some more metrics.
If you change the names of the inputs in the form most probably the request will be successful, to wit you will get HTTP Status Code below 400 hence JMeter will mark the result as "green", however if you inspect the response using View Results Tree listener you will see that the form is not filled and/or you still at the same page.
If you want to use JMeter for checking the data returned by the application you're testing consider using JMeter Assertions to test presence of expected values, absence of errors, set response time thresholds, etc.
You can automate the form submission or order placement usin JMeter. You can JMeter for API testing as well by adding assertions. But the main purpose of the JMeter is to test the performance of the application. Its not like selenium which performs actions on the browser whereas JMeter sends the request in various protocols to relevant server and can also simulate many users at the same time.
If you want to do extensive automation testing,JMeter isnt the ideal tool for that.
You can use webdriver sampler to run the selenium with jmeter. It requires to configure sampler and browser config which are plugin and can be downloaded using plugin manager.
For more info:-https://www.blazemeter.com/blog/jmeter-webdriver-sampler/
Now, without the plugin it is working on protocol level and not on the frontend as pointed out in the above comments.
So, yes it can depend on which layer you want to work. It can work on frontend like selenium using the webdriver plugin and can submit the form with different data as a direct request to the server without using the frontend/GUI.
Hope this helps.
It depends on what you are trying to automate. If you plan to automate API invocation where there are some pre-requisites like grabbing tokens, cookies, session IDs from the browser, then JMeter can probably be used where existing JMeter capabilities can be leveraged using BeanShell scripting and other plugins.
But if you plan to have a full blown UI automation framework then JMeter might not be an ideal choice.

Run the recorded testplan in Jmeter and verify the the entry in the Database

Im using Jmeter and do performance testing for my web application. I record my actions in jmeter and play back the same. The testplan got run but when i verify the database manually, the new row is not created. The value got added in the existing line.Please help me out of this. I am struck in this step for 2 days
Verify if your requests includes hardcoded session's data. If your app manages sessions and you just "recorded" the actions, probably you are re-using the same session's data. Assuming there is a login page -> the requests after the login would use a session, usually returned for the login action.
As comments are not enough descriptive; posting a new answer. You can do this by using regular expression extractors, because -probably- the session info comes in the response (so extract it into a variable, by parsing the response with a regex extractor)
and then use the variable in further request/s.
This is a tricky way and need lot of work... even more if the session keep changing in subsequent responses (it usually change while moving worward through the page/app workflow), if that is the case you will need to extract the data after each request.
Please reffer to the jmeter manual for more info about regex extractors.

Jmeter: Issue with Response Data (HTML) and Is my script Functional?

I am using Jmeter(2.3.2) to create script for one of my application with a scenario which has flow for 4 to 5 pages. I have recorded the script using HTTP Proxy Server. The scripts has been generated successfully under Thread Group >> Recording Controller.
After running the scripts (Threads- 1, Ramp Up period - 1, Loop Count - 1 ), below are the observations I noted in View Results Tree:
The Result Tree view shows all as Checked(Green) - OK
The Sample result for all screens shows Error Count as 0 - OK
But in the response tab when I try to view the results by using 'Render Html' response data - the response data shows the same response for all the requests.
I am getting the response data of the first request for all the other requests.
I am not sure, whether the Jmeter script generated is functional or not? What is the cause for getting the same response data for all the requests?
Please, can anyone let me know what may the issue?
I bet that the same page you're observing is a kind of login page or dashboard which is accessible by unauthenticated user.
First of all make sure that you have HTTP Cookie Manager added to your test plan. It represents browser cookies and deals with user sessions and cookie-based authentication.
If it doesn't resolve your issue the problem is bigger and you will need to do some extra stuff. Modern web applications use multiple mechanisms of current state of things storing and managing, security enhancements and so on. From JMeter's point of view it results in dynamic mandatory parameters. The process of these dynamic parameters extraction from previous request and adding them to next request is called "correlation". So you need to do the following:
Detect which parameters being sent by a recorded script are dynamic. The easiest way is to record the same scenario several times and inspect request bodies to see what is being static and what changes.
Once you figure out which parameters are "interesting" you need to locate them in the first response body/headers/etc.
As soon as you have identified what necessary parameters are and where they live you need to use one of JMeter's PostProcessors to extract required values from previous response and save them to JMeter Variables
Once you have a JMeter Variable it can be used wherever required.
Depending on response data type the most commonly used JMeter's Post Processors which provide correlation capabilities are:
Regular Expression Extractor - the most commonly used test element which covers >90% of needs.
XPath Extractor - better to use against XML data i.e. for testing SOAP Web Services.
CSS/JQuery Extractor - when you need to fetch something from complex HTML where Regular Expression Extractor is useless.
So for putting everything together loog for "jmeter correlation" in your favorite search engine or see ASP.NET Login Testing with JMeter guide.
First JMeter 2.3.2 is WAY TOO OLD (10 years old), upgrade to JMETER 2.11.
Second, Jmeter cannot guess that the response if KO if the returned code is 200, so you need to add Response Assertion that will check for some text you expect in the page.

Header Manager and Recording Controller

In my test scripts, I use a header manager that is shared at a thread group level, and then each sampler has it's own header as well for things that change (referrer, certain pragmas and cache-control) from request to request. I do this for ease of control e.g. so I can easily change the user agent for all requests.
I use the proxy and a recording controller to make the majority of my scripts, and I have set a header manager as a child of the recording controller - I have also tested this by setting a header manager inside the proxy element, but neither of these work as I want.
What it is doing is adding in a full set of headers from the browser, and not just those missing or different than what I have specified in the header manager.
Am I missing something, or is there even a way to do what I am trying to do?
I am using jmeter 2.6.
As others have pointed out, this doesn't happen yet in Jmeter. I am using 2.7 and see the same behavior.
I believe the original intent of the HTTP Request Defaults and HTTP Header Manager was to ease the task of developers creating scripts by hand. With the increased usage of the HTTP Proxy Controller, the application of the the above two elements needs to be extended to the Proxy Controller as well for recording.

Resources