In jmeter want to add 2 parameter into body(Json).Record and replay is working,but want to pass 2 parameter in Json,so can pass values from CSV file - jmeter

I am working on one of the JMeter script and I have one question regarding an item. If I want add both the parameters into body data(Json format) then how can I do? When I record and play it is working fine but I want to modify the script by passing both parameters in Json format, so that I can pass the values from CSV file
Please see screenshot:
One of the value is Json format and other one is button. I know how to pass the multiple values but here one of the parameter is button.
I have passed both the parameters into body data and tried replaying the script but not able to do it with the button parameter. please help here

Your screenshot is not visible.
JMeter doesn't know anything about HTML buttons, it acts on HTTP protocol level
If you want to have the possibility to parameterize any data which is being sent by JMeter just put this data into the CSV file and replace the recorded hard-coded values with the variables defined in the CSV Data Set Config.
Use Debug Sampler and View Results Tree listener combination to see what are the JMeter Variables values and how does request look like. You will also have the possibility to compare the recorded and parameterized requests.

Related

Jmeter can get parameters?

My question is - if I run a test via Jmeter, for example , if it's a site which enables you to book a flight, and you choose your source and destination when you record it.
Is it possible to pass different values to the destination field? I mean, maybe a txt file with some destinations and pass it to the Jmeter test and then, you will have some tests which each of them is running with a different destination?
If yes, how can I do it?
It's not necessary that it will be a txt file. Just a way to pass different values to one parameter.
Important: I'm using blazemeter plugin for chrome.
Thanks a lot,
appreciated.
You can use CSV Data Set Config. It is very easy to use for parameterizing variables in the test plan.
Check this article on blazemeter to understand the CSV Data Set Config quickly.
Depending on what you're trying to achieve you can go for:
HTML Link Parser. See Poll Example which shows how you can use it for selecting random values from inputs
You can extract all the possible values from the previous response using a Post-Processor, most probably CSS Selector Extractor and configure each thread to use its own (or random) value from the input
And last, but not the least, you can use an external data source like .txt or .csv file and utilize __StringFromFile() function or CSV Data Set Config so each thread (virtual user) would read the next value from file instead of using recorded hard-coded values.

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 read random data for each request in JMeter

I have 4 input parameters which I need to pass in my http request sampler. Everything is OK but the problem is how to first data i have to pass from the previous thread http response and rest 3 from the csv file. Please help.
It seems that you want to update a specific value of the CSV during execution. It would be wise to say that this can be achieved using if controller and User Parameters element. You can go through the below screenshots to resolve this problem.
CSV Data set config for reading csv values
CSV File
Here, I have added text "REPLACE_WITH_RESPONSE" so that we can match it in IF controller.
IF CONTROLLER
This will check if you want to replace this value or not.
Users Parameters
This element would be used to update the csv value with previous request response. In the below example, Date is the CSV value which is replaced with previous Response.
Hope the above solution will help you in resolving this problem.

Passing whole body as a variable to a POST request

I'm trying to create a simple stress test using JMeter. I have mostly GET requests and a couple POST requests. My main goal is to make this test as reusable as possible. I want to implement it in a way that the user would have to provide a CSV file with the following headers:
method;path;postBody
The values would look something like:
GET;/path/to/resource;''
POST;/path/to/resource;'{"key":"value","key":"value","key":"value"}'
Now POST (PUT, PATCH etc ..) bodies differ from one request to another. Providing ${postBody} to Body Data tab does not work "${postBody}" as well.
Is there a way to achieve this? Command line solutions are more than welcome as well.
EDIT: To clarify, I'm using the UI interface. When I input ${postBody} in the Body Data tab the UI complains. When switching from the Body Data tab to another one I get the following prompt:
Remove "'" around the request and it should work.
Regarding the warning you get, it is not an error, it is just that in JMeter those 2 tabs are exclusive:
Parameters tabs is for input of parameters in the form as name=value
Body data is for your kind of requirement
So can you test my hypothesis which is to remove the quote around the request in CSV file ?
If it still fails, please show the logs.
You can remain in Body Data tab,
Add after pathPost your optional query parameters for GET request:
${pathPost}?${getPramaters}
Don't worry about the ? it's just seperate path from parameters
Also consider changing variable name to path, more suitable because it can be POST.
In JSON , seperate between values while in CSV default is also ,
I suggest you can your CSV delimiter, In CSV Data Set Config Choose different Delimiter as ; and add your data in CSV accordingly (remove extra ' characters):
POST;/path/to/resource;{"key":"value","key":"value","key":"value"}
Notice: Allow quoted data keep default value False

Want to save Correlated variable locally in Jmeter

I want to save correlated variable locally (localdrive) then i might need to edit that variable with other dynamic value and then i should send it to subsequent request in Jmeter.
Please suggest me a way to perform the same.
Correlation in JMeter works as follow:
Add a Regular Expression Extractor on the sampler that contains the data you want to extract, example:
JMeter will automatically add a variable QUANTITY that will contain the extracted data
If you want to modify the variable you will use a JSR223 Sampler
In the next sampler you can use the data as ${QUANTITY}
No need to store anything on disk.

Resources