jmeter functions and variables from csv not substituting - jmeter

I have a POST request setup in jmeter that has a body like:
"chartId": ${chartid},
"source": "Direct 5",
"documentId": ${__counter},
__counter is a built in function and chartid should be coming from CSV:
However, they are not being substituted in the request. I'm using the latest jmeter (5.5) with Java 8.
Can anyone think of anything I might be missing?

${__counter} is not a built-in function, ${__counter(,)} is. Use Functions Helper Dialog if you're uncertain regarding proper functions syntax.
I cannot comment anything regarding ${chartid} unless I see first 2 lines of your CSV file and the rest of configuration of the CSV Data Set Config, in the meantime you can see all JMeter Variables which are defined with their respective values using Debug Sampler and View Results Tree combination

Related

Jmeter how to read file path within csv file

Is it possible to pass in file path or read from another file within csv? My test setup is something like that.
Jmeter Test
Http request -> body data -> "items": "${__property(${items})}",
CSV data config
Id,Name,Items
1,MyName,\input\items_json.txt
I want to include a file in csv items column and in jmeter test, it will read and post items json.
Got it working with this.
"items": ${__FileToString(${__property(${Items})},,)},
Not really, being a Configuration Element CSV Date Set Config is initialised before anything else so you will have to consider another approach, i.e.:
__CSVRead() function
__StringFromFile() function
__FileToString() function()
Functions are being evaluated exactly where they're called so this way you can use them for parameterization. See Apache JMeter Functions - An Introduction to learn more about JMeter Functions concept

On using a CSV config with JSON data the quotes are read incorrectly for the key value pair

I have a POST data from CSV used in excel
{"Name":"","Token":-1,"TimeScheduleToken":"1","AccessRule":[{"ObjectToken":"528","ObjectName":"Common_ wash_Room_Exit","RuleToken":"528","RuleType":2,"StartDate":null,"EndDate":null,"ArmingRightsId":null,"ControlModeId":null}]}
When performing a post-execution the JSON data in the request is not as same as from the CSV. Find the request in the image
Quotes given for the key value pair is doubled up and showed in the request. How to resolve this, kindly suggest
Vittal,
I have tried to reproduce your issue in JMeter 3.3 and noticed that its working fine. Please find below the settings that you need to do in 'CSV Data Config' element.
Moreover, I would recommend that when you are creating any csv file for the data then open the notepad and enter your data and then save it as .csv file to avoid any unnecessary elements/characters in the data.
You can also refer to the blog post to get more information on API load testing using JMeter: JMeter Load Testing Against APIs
I have no idea regarding how you're getting these double quotation marks, however here is how you can remove them in the runtime:
Add JSR223 PreProcessor as a child of the HTTP Request sampler
Put the following code into "Script" area:
def originalData = sampler.getArguments().getArgument(0).getValue()
def normalizedData = originalData.replaceAll("\"\"","\"")
sampler.getArguments().removeAllArguments()
sampler.addNonEncodedArgument("",normalizedData,"")
sampler.setPostBodyRaw(true)
That's it, the JSR223 PreProcessor will replace all occurrences of double quotation marks with single quotation marks.
sampler is a shorthand to parent sampler class implementation, in case of HTTP Request sampler it would be HTTPSamplerProxy, see class documentation for all available functions and properties.
See Apache Groovy - Why and How You Should Use It article to learn more about using Groovy scripting in JMeter tests.

jmeter prev.getResponseDataAsString getting wrong return

I have a looping process that will extract some values from a web service (working) and loop through to pull all the information for each value (working).
I need to capture the whole return into a variable so I can modify it and post it back up later.
Screenshot:
When the "Baseline for ..." get kicks in, I get the proper response
But the "Get response" BeanShell PreProcessor is picking up old responses
Screenshot:
Given where my "Get response" object is, I would assume the:
vars.put("ResponceData", prev.getResponseDataAsString());
...would grab the response from "Baseline for ${ID} of site ${callSite}". Please help!
You are using wrong test element. Beanshell PreProcessor is being executed before request therefore it acts properly and returns response from the previous request instead of current one. You need to change it to the Beanshell PostProcessor and your code will start working as you expect.
It is recommended to avoid scripting where possible, if you need to save response data into a JMeter Variable you can do it using i.e. Regular Expression Extractor. According How to Extract Data From Files With JMeter article the relevant configuration will be something like:
Reference Name: ResponceData
Regular Expression: (?s)(^.*)
Template: $1$
If you face a JMeter limitation which cannot be worked around without using scripting make sure you are using the most performing scripting language, since JMeter 3.1 it is recommended to use JSR223 Test Elements and Groovy language

Print response json in jmeter using beanshell

I want print my json response in jmeter. I used beanshell but it shows error. Below is the line to print json object extracted in "data":
log.info("========"+${data});
Don't ever inline JMeter Functions or Variables into scripts, they may resolve into something which will cause compilation/interpretation failure, use code-based equivalents instead or pass functions/variables via "Parameters" section.
Exhibit A: using vars shorthand
log.info("========" + vars.get("data"));
Exhibit B: using "Parameters" section
Using Beanshell isn't the best scripting option, consider migrating to JSR223 Elements and Groovy language as Beanshell has known performance problems. Moreover, Groovy has built-in JSON support See Apache Groovy - Why and How You Should Use It for details.
And finally your ${data} variable might not be defined (i.e. your extractor fails), in this case you will get interpretation failure on attempt to refer it as ${data}, double check its value using Debug Sampler and View Results Tree listener combination.

How to parameterized request if getting recorded script like this.? See details

How to parameterize request if I am getting something similar to the following for login POST request in body data tab.
"{\"msg\":\"method\",\"method\":\"login\",\"params\":[{\"user\":{\"username\":\"testuser\"},\"password\":{\"digest\":\"5811c74a581ffdb892ab9eddfb9cf2d21772a98332a59de6aa26989e01f84057\",\"algorithm\":\"sha-256\"}}],\"id\":\"7\"}"]
It's generally easy to correlate when we are getting in Parameters TAB, but in cases how we can proceed? For all further requests - it's the similar case.
I tried to switch to Parameters TAB, but it says that it can not be converted to that format.
So How we can proceed?
The same way, just substitute hard-coded (recorded) values with the relevant JMeter Variables directly in the request body like:
"{\"msg\":\"method\",\"method\":\"login\",\"params\":[{\"user\":{\"username\":\"${username}\"},\"password\":{\"digest\":\"${password}\",\"algorithm\":\"sha-256\"}}],\"id\":\"${id}\"}"]
The most commonly used for parameterization test element is CSV Data Set Config, however other options exist.

Resources