JMeter - using UDV for post json body - jmeter

Using JSR223 Sampler, I read contents of my payload file, appended ${loop} variable to its contents, and stored whole of payload data into a user defined variable "payloadAsString"(via vars.put())
Can I use this variable in my HTTP Request sampler's 'Body Data' section as ${payloadAsString} ?
By this, I am expecting the content stored in the variable, along with the 'loop' value in it, to be incremented,during run time.
please advise.

Related

In JMeter when I try to pass the variable assigned with JSON extractor to the subsequent request null value is passed

I do a POST request using Jmeter and I parse the JSON response using the JSON extractor. When i use the debug sampler I could see the Variable is assigned with the value properly but that value goes as null in the subsequent request
Below is the request URL for the next sample /XXX/XXX/XXX/XX/${recordingjobid}
but this value recordingjobid is not substituted with the value.
I can only think of not proper placement of the JSON Extractor.
For example if you have it at the same level as several samplers - it will be run after every of them (including the Debug Sampler) and each next one will be overwriting the value set by the previous one as JMeter Variables are local to the thread and don't allow duplicates.
So my expectation is that if you move the JSON Extractor to be a child of the request which returns the JSON - it should resolve your issue.
More information: JMeter Scoping Rules - The Ultimate Guide

How to replace blank " " cell to null without quotes in jmeter while reading data from csv in HTTP Request body? data

I have data in csv and somewhere cell value is blank and when I am using this blank value in my HTTP request body data then it is replacing like "", but I want to replace as null without quotes. Please help here.
PFA snapshots
1
2
3
You can do it dynamically using i.e. JSR223 PreProcessor and the following Groovy code:
def body = sampler.getArguments().getArgument(0).getValue().replaceAll('\"\"','null')
sampler.getArguments().removeAllArguments()
sampler.addNonEncodedArgument('', body,'')
sampler.setPostBodyRaw(true)
Add JSR223 PreProcessor as a child of the HTTP Request and it will replace blank values with nulls.
Where sampler stands for HTTPSamplerProxy class instance, it provides access to request body, url, headers, cookies, etc.
The other simple solution to resolve this problem is to use "" in the test data itself.
Check the below screenshots :-

How to Map RegEx variables with BodyData fetched from CSV Files

CSV Data Config from JMeter contains following -
File.csv Contains following
GetAllOrderItems.txt contains following
{"dataRows":[],"orderGuid":"${orderGuid_1_g1}","facilityPk":"0","jtStartIndex":0,"jtPageSize":100,"jtSorting":"SKU ASC","isMap":"1"}
orderGuid_1_g1 is fetched from Regular Expression extractor
I passed following to JMeter body data
When I execute JMeter test, I can see follwing
{"dataRows":[],"orderGuid":"${orderGuid_1_g1}","facilityPk":"0","jtStartIndex":0,"jtPageSize":100,"jtSorting":"SKU ASC","isMap":"1"}
However, I want ${orderGuid_1_g1} to be fetched from Reg Ex of previous HTTP Request.
I want following
{"dataRows":[],"orderGuid":"644e1dd7-2a7f-18fb-b8ed-ed78c3f92c2b","facilityPk":"0","jtStartIndex":0,"jtPageSize":100,"jtSorting":"SKU ASC","isMap":"1"}
Code works well, If i did not fetch Body data from text and directly insert below code inside body of HTTP Request
{"dataRows":[],"orderGuid":"${orderGuid_1_g1}","facilityPk":"0","jtStartIndex":0,"jtPageSize":100,"jtSorting":"SKU ASC","isMap":"1"}
If your file contains nested JMeter Variables you need to wrap your __FileToString() function call in __eval() function like:
${__eval(${__FileToString(${GetAllOrderItems})})}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables
JMeter does not interpret variables when you load content from a file.
Besides, for a load test using __FileToString function is not advised unless it is used for setup for example which is not the case here.
So just put the JSON Body request in the request body, it will be better for readability.
If you still want to do that, follow Dmitri Answer.

Dynamic variables use with file upload as in the body of the HTTP request JMeter

I am uploading a file [.xml] to be the body of the POSt HTTP request. But the file has a variable ${TEVAM} whose value is being fetched from the previous request and being assigned.
But the value is not being replaced.
What should I use here?
In order to get the nested variables resolved you need to use __eval() function as a wrapper for i.e. __FileToString() function like:
${__eval(${__FileToString(test.xml,,)})}
More information: Here’s What to Do to Combine Multiple JMeter Variables

Passing Multiple JSON parameters in JMeter

My registration form is accepting body in JSON format, and I need to run the test with 5 different user names.
How do I pass JSON as request body? Also I was unable to pass parameter from CSV file. How can I solve this issue?
Add CSV Data Set Config to your Test Plan
Configure it like:
Filename: full path to the file with your emails
Variable Names: anything meaningful, i.e. EmailId
In your HTTP Request sampler copy the recorded value to Body Data" tab and replace hard-coded email with JMeter Variable like:
{"EmailId" : "${EmailId}"}
In Thread Group set "Number of Threads" to 5
Next time you run your test JMeter will read next line from the file.csv and substitute the ${EmailId} variable with the value from the CSV file.
See Using CSV DATA SET CONFIG article for more information on parameterising your JMeter tests via CSV files.

Resources