Automate sending a request and saving the response - jmeter

There is a URL which I want to hit and save the response. The URL id needs to be incremented each time and save the response. For example -
First Get Request - http://google.com/getdata/?Id=1
First Response - one
Second Request - http://google.com/getdata/?Id=2
Second Response - two
and so on...
I want to hit the request with increment the id each time and save the response
I have tried using fiddler but unable to figure how to increment the id and save the response.
P.S. - I have to make around 6,00,000 hits

Since the 'Postman' tag is mentioned, I can help you regarding how to implement this in Postman.
Postman has a nice feature of using 'variables'.
You can use environment variables or globals.
Read more about these on their docs:
https://www.getpostman.com/docs/v6/postman/environments_and_globals/variables
You can use a global variable such as 'counter' and set it to 1 / whatever starting point you want.
Then you can modify your request like so :
http://google.com/getdata/?Id={{iteration}}
Now, in the Tests script of the request you can write the following script
let i = parseInt(pm.globals.get('iteration')) + 1;
pm.globals.set('iteration', i);
Also, to access the response you can use the following command in Test script:
console.log(pm.response); // Use pm.response as per your needs
Save the request in a collection.
Now load the Postman's Runner and select the collection.
Now you can put an iteration count of 6,00,000 and hit run!
Remember, heavy iterations will cause performance degradation.

In JMeter you need to click , Ctrl+0 and Ctrl+1 to create , Thread Group and HTTP Request
In Thread Group put the number of hits you need in Number of Threads (users)
In HTTP Request Put in Server Name or IP www.google.com and in Path /getdata/?Id=${__threadNum}
__threadNum will create increasing number from thread 1 to number of hits.
For small number of hits or debugging you can add View Results Tree to view request/response by clicking Ctrl+9 in Test Plan/Thread Group level.
To save the response use Post Processor, especially by adding Regular Expression Extractor below HTTP Request by clicking Ctrl+2.
Allows the user to extract values from a server response using a Perl-type regular expression. As a post-processor, this element will execute after each Sample request in its scope, applying the regular expression, extracting the requested values, generate the template string, and store the result into the given variable name.
Import to notice that for load testing you need to work with non GUI mode, which means call jmeter using command line as jmeter -n -t myTest.jmx
you will use Command-line mode (called Non-GUI mode) to run it for the Load Test.
Don't run load test using GUI mode !
For saving all responses to a one file see save response data or if you want to save file per thread/user you can add Save Responses to a file

Fiddler:
Open script editor (Control + r ) then add the following code inside OnBeforeResponse
static function OnBeforeResponse(oSession: Session) {
if(oSession.oRequest["X-SAVE-ME"] != "")
{
oSession.SaveResponseBody("C:\\tempfiddler\\" + oSession.SuggestedFilename);
}
}
Go to the "Composer" tab and include the header X-SAVE-ME with any value, in the URL, replace your ID with # (just like this: http://google.com/getdata/?Id=#) fiddler will now ask for the starting and ending value of ID before executing;

Please find the snapshot below for your scenario.
Scenario_Testplan
First, go to user properties and put "sample_variables = ID, Response_File_Name" or whatever the name you choose for the variables. Restart jmeter.
Create the below plan:-
CSV data set config to have incremental values and response file name
HTTP request will use ${ID}
Save response to a file will use ${Response_File_Name}
Hope this will help.

I would do this by command line, using a while loop with a curl to the URL, storing the body result on the standard output to a file. It would look something like this:
for i in {1..600000}; do curl "http://google.com/getdata/?id=$i" > body-result-id-$i; done
I couldn't test the line above because I don't have any access to a console right now, but I think it should work.

In Burp you can do this using the Intruder tool. First, capture a sample request in Burp. If you're unsure how to do this, please consult the getting started documentation.
Then right-click the request and selected "Send to Intruder".
In the Positions tab within Intruder, first click "Clear" then select the section you want to vary, and click "Add"
In the Payloads tab select the Payload type as "Numbers" and configure the range.
Click "Start attack"
For more information, consult the documentation.

One Another solution is that you can use Counter in jmeter. That you can find from below path
Thread Group > configElement > Counter.
Configure the Counter as per your need.
Give the Reference Name i for counter.
Use the variable in your request
For more information.

Related

how to save whole response message in jmeter

I am receiving below response in jmeter-
[{"Status":"Failed","ErrorDesc":"Duplicate Transaction Id","Amount":"23","CorporateID":"aaa","StatusCode":"ERR0DUP","TransactionReferenceNumber":"1111"}]
I need to save this whole response message.
I tried by using listner,and using csv file as well but only b able to save response like - OK,true
Please help me to save whole response as it is.
You could use the Save the Response to a File Sampler with following configuration
Ensure "Don't add number to prefix" check box is not checked
Set the Minimum Length of sequence number (e.g 6)
You can try with following options for unique file names
Check the Add timestamp
Use ${__threadNum} and/or ${__threadGroupName} fields with file name
response-${__threadGroupName}-{__threadNum}.json
If you want to save response into a variable just use Boundary Extractor with empty left and right boundaries or Regular Expression Extractor and (?s)(^.*) regular expression, see The Boundary Extractor vs. the Regular Expression Extractor in JMeter article for more details to learn more about differences of these two guys.
Example setup:
in the above setup the whole response will be saved into a JMeter Variable and you will be able to refer it as ${response} where required
If you want to save response into a file - go for Save Responses to a file listener, add it as a child of the request which returns the response and configure it like:
the above configuration will store the whole response of the parent sampler into response.txt file in "bin" folder of your JMeter installation

Dynamic Refid is appended to the URL but i can't find refid in the response

When i perform the action on UI a dynamic refid is appended to the URL using query string parameter. I can't find that refid in the response but its part of the request. In the code i only found the variable.
Here is the URL on UI.
https://XXXXXX.XXXXXXXXXXXX.com/Recruiter/#!/candidate/new/157072048
I captured the Get request for the same action using the developer tool on Chrome and it looks like this.
Request URL: https://XXXXXX.XXXXXXXXXXXX.com/Pages/candidate/new.aspx?refid=157072048&mode=quick
This Get request has 2 query string parameter.
refid: 157072048
mode: quick
Now i need to captured that refid and pass it the step 2 to be able to create that record. I need help to figure this out.
I found comment in the html that may be help full.
// referenceid - only used with the "Web" app, gets mapped to "&refid=123" in the query string, and ends up as Page.ReferenceID in WebForms.
If this is not a part of a response data then it might be the case it's generated on the client by JavaScript code. You need to figure out how the value is being generated and replicate the same code using JSR223 Test Elements and Groovy language.
Another possibility is that the value comes from an Ajax request which JMeter doesn't execute because it cannot execute client-side JavaScript. In this case you need to simulate the same request and extract the value from there.
And last but not the least, the number you're looking for may reside in one of the sub-samples which may appear as the result of Redirection and you're trying to find it in main sampler response:

field name is getting changed in response data

Field name is getting changed after executing the script.
A. After executing the script,the field name is not getting displayed in response data but the parameters are displayed with slight changes.
In sampler below details are getting displayed.
Name : aura.token
Parameters : HCQAHBgEMTAwMBQCGAcxMDAwMjA5GAcxMDAwMjA5ABQCGfMQscHV8XF654tDbfY0XD3yRxaSwbvRh1oAGfMgzIG_YaBrAZdWB-IAMP_0iAQiYMHheBA3BA0SoXzWh4kA
but after execution of a script below details are getting displayed in response data.
*/{"event":{"descriptor":"markup://aura:invalidSession","attributes":{"values":{"newToken":"HCQAHBgEMTAwMBQCGAcxMDAwMjA5GAcxMDAwMjA5ABQCGfMQkaKR6n5r5QqE7gz5Qk1l1Rb67KOtiFoAGfMgtKaMHHWJZiXEOt8pU6zs1edK_Q4dQo5VL2ea8y2qi3gA"}}},"exceptionEvent":true}/*ERROR*/
It's name is "newToken". So why do you think this should not be changed?
Most probably you need to perform correlation of this field, to wit you will not be able just to record and replay the script as this "token" is being generated dynamically and has new value each time you access the application.
The main idea of the correlation is
Identifying dynamic elements. The easiest way is to record your test scenario one more time using HTTP(S) Test Script Recorder and compare the recorded scripts. All parameters which are different needs to be handled properly.
Wherever you detect a dynamic parameter look into previous sampler response data (body, headers, Cookies, URL) - the value should be there
Apply a relevant Post-Processor to the previous sampler in order to extract the dynamic value and store it into a JMeter Variable
Replace recorded value with the JMeter Variable from the previous step
You should be good to go now.

how to run multiple urls in jmeter and it should display on one screen

i am new to jmeter. i would like to run multiple urls at one shot and display the results on one screen. finding hard to config urls through csv file and in jmeter.
my sample url:
http://10.56.34.67:7065/services/sample/2070
http://10.56.34.67:7065/services/sample1/2070
http://10.56.34.67:7065/services/sample2/2070
like this i have more thn 100 url to test it.
could you please tell me the format to store urls in csv file and how to config the csv file in jmeter?
It has simple as
Click Ctrl+0,Ctrl+1 which adds Thread Group and HTTP Request in side
In HTTP Request add ${path} to Path field
In Thread Group choose Loop Count Forever
Add CSV Data Set Config by right click on Thread Group -> Add -> Config Element
CSV Data Set Config parameters :
a. Put the fileanme in Fileanme field
b. Enter in Variable Names path
c. Choose Recycle as False
d. Choose Stop Thread as True
Click Ctrl+R (run)
It will go through all URLs and submit them sequentially
To view results you can add View Results Tree (Click Ctrl+9) and you will see all your requests/responses.
It seems your data here is your URLs.
So instead of using multiple samplers for each URL, you can go for CSV Data config and store all your URLs there and name the column as URL.
you can refer to this in your single http sampler as ${URL}.
Your CSV should look like this
In Server name put ${URL} and in the Thread Group check the forever check box
You don't need CSV for this use case, the easiest way would be going for __StringFromFile() function.
In the HTTP Request sampler put the __StringFromFile() function into "Path" input field like:
The textual function representation is ${__StringFromFile(urls.txt)}, you will need to replace urls.txt with full or relative path to the file where your URLs are listed
That's it, each time the request is called JMeter will read the next line from the file and substitute request path with the string from file:
See Apache JMeter Functions - An Introduction article to get familiarized with JMeter Functions concept

jmeter how to replay recorded unique id from application

I am very new to Jmeter and trying to use it for doing load testing my application.
In my application, every time we click on a template, application will allocate a unique id which to the template...when I recorded the steps using jmeter, a particular unique id was recorded...but when I tried to play the recorded case...it is looking for the same unique id....how do I tell jmeter to get the new id from the application?
Here are the steps
Login as a user,
click on a particular link,
click on a button which will then popup a window asking to select a template,
After selecting a template, my application will create a unique id for that template
It very much depends on whether that template ID is created on the client (i.e. by JavaScript), or on the server (i.e. you can actually record a template ID returned by the server).
If second is your case, then server returns template ID in the response to template selection, so you can use one of the post-processors - a supporting element invoked after the parent request; it usually extracts data from the response and saves it as a variable(s). In your case you'd extract template ID and save it as variable. Later samplers can use the variable in format ${your_name} instead of the recorded hard-coded string. So in that case your plan could look like this:
Which post-processor to use and how to use it depends on the response you are receiving form the server, so cannot be more specific here.
If the first option is your case (JavaScript on the client generates template ID; and your recording only contains usage of said ID), then you can simulate what JavaScript is doing by generating a similar ID using one of the JMeter script-related features: it could be random function, an inline piece of JavaScript code, a scriptable sampler, such as JSR223 Sampler, or... There are many options really, depending on concrete needs of that generated template ID. Again, a more specific question would help to narrow down your choices.
Classic "correlation" example.
Look for that generated ID in the previous responses (you can do it with the View Results Tree listener)
Once you detect it you need to extract it and convert into a JMeter Variable with a PostProcessor (the most commonly used is Regular Expression Extractor, however depending on the nature of your request you may consider to use others
Once you get the ID extracted and stored in the variable - substitute hard-coded value obtained via recording with the JMeter Variable
Repeat steps 1-3 for any other dynamic parameters or values. Or, consider a faster way of creating a JMeter test via alternative recording solution which performs the above steps automatically so you won't have to worry about detecting and handling dynamic elements. See How to Cut Your JMeter Scripting Time by 80% article for details.
You need to check response of the previous request. Normally ID will be created and can be found in the response of previous request and you can use that ID for next request.
You need to first find in which response the ID is being generated and the format of the ID. You can use firebug to see the response in HTML format and find where the id is.
Once you have the format of the id, create regular expression around it. Test it using regex tester that comes with JMeter. Or you can use rubular.com to check the correctness of your regex.
Once you have correct regex, use regular expression postprocessor on the request which returns the id and then use that variable in actual request that uses unique id.

Resources