logging property value in jtl log file - jmeter

I have been using "sample_variables" to print custom variables in jtl file.
I would also like to print custom parameter using this approach.
But specifying property as -
-Jsample_variables=prop1,prop1
does not log corresponding value in jtl file. And I see only null values in log file.
Is there a way to log properties in jtl file
UPDATE -
I converted the variable into property using User Parameters and test runs good but yet the variable value is not printed in jtl log. There is always null value printed for sample where variable is used. Test Plan looks as -
And I added following line to run script -
-Jsample_variables=verifytoken \
But verifytoken is always null for sample - getTokenInfo
Did I miss any configuration?

Convert properties to variables using __V() and __P() functions combination or __property() function like:
${__V(${__P(prop1,)})}
or
${__property(prop1,prop1,)}
Functions can be called in any place of your JMeter script.
References:
Functions and Variables
How to Use JMeter Functions

Related

how to pass the dynamic filename in csv data set config in jmeter while the dynamic names are generated to save data of previous request?

I have one http request whose response comes in nested json and using groovy i am saving that data in different csv file on the basis of conditions.
the name of csv file is generated dynamically and saved in a variable
using vars.put() function
vars.put("_cFileName",cFileName.toString());
when try to use this variable in csv data set config
enter image description here
getting error message
2022-01-19 16:58:39,370 ERROR o.a.j.t.JMeterThread: Test failed!
java.lang.IllegalArgumentException: File ${_cFileName} must exist and be readable
it is not converting the name to actual file name
But in case if file name is not dynaamic and the variable is defined under user defined variable in test plan it will able to convert to actual file name?
is there any way we can use the dynamic name created in an previos request post processor?
You cannot, as per JMeter Test Elements Execution Order Configuration Elements are executed before everything else, CSV Data Set Config is a Configuration Element hence it's being initialized before any JMeter Variables are being set.
The solution would be moving to __CSVRead() function, JMeter Functions are evaluated at the time they're being called so it's possible to provide dynamic file name there, see How to Pick Different CSV Files at JMeter Runtime guide for more details if needed.

Graphql in jmeter

I am using graphql in jmeter for API testing. Where in graphal we have the query and variable section.
My query would require a client ID which is int. Where as in Variable if I try to pass "{clientid : ${clientid}}"(here I am passing the CSV config variable, for testing the app for multiple users). But it is throwing an error like $ is unauthorised and expecting a (json,null,true or false).
Please help me out how I can pass the clientid which is a csv config variable.
Thanks in advance.
It looks like your CSV Data Set Config setup is not very correct so the JMeter Variable placeholder isn't getting substituted with its respective value from the CSV file.
We cannot help without seeing first couple of lines of the CSV file and your CSV Data Set Config setup so far I can only suggest re-visit the configuration and cross-check it with JMeter Documentation
You can observe JMeter Properties and Variables with their values using Debug Sampler and View Results Tree listener combination, if you don't see clientid line there - the variable is not set and JMeter sends it as it is, to wit "{clientid : ${clientid}}" and doesn't substitute ${clientid} with the value from CSV

Jmeter - CSV Data Config file name - Modify at RunTime

How can I change the filename of the CSV DataConfig at run time in the jmx file.
We have a logic in a java class which would create a dynamic file name and this
needs to be configured as the filename in the CSV DataConfig.
I am using Jmeter 4.0
Regards
You could use a variable / property name in the CSV data set config
here filename could be the name of the file or complete path of the file itself could be used as a variable.
Remember that CSV Data set config element gets initialized first - so filename should be a User defined variable / could be a property passed to JMeter. I would prefer a property.
Do note that You can not keep on changing the CSV data set config element filename in a test once it started. That means one CSV Data set config element can be used for 1 CSV file only. We can not modify!!
You cannot as CSV Data Set Config is a Configuration Element therefore it's executed before anything else. If you need to read the data from different files as the test goes by consider using JMeter Functions instead, the most suitable ones would be:
__StringFromFile() - returns the next string from the given file each time it's called
__CSVRead() - reads a value from CSV file. The function not only supports using dynamic file names, moreover, you can provide even multiple input files as well.

Load properties file in jmeter then assign properties value to JMeter variable

I have condition where I need to load properties file and assign prop value to JMeter UDV.
I have been able to load property file successful, however I can not assign prop value to UDV
I have try the following:
Load prop file contain key value (i.e var_from_prop_file=1000)
Create UDV (with keyname "my.var" and value "${var_from_prop_file}")
Run debug script with debug sampler, I can see var_from_prop_file assigned to value 1000
However my.var still empty (no value).
my expectation when creating UDV with my.var = ${var_from_prop_file}, my.var value will be 1000 too, but it doesn't happen here.
I have try with __eval and __evalVar - no luck so far.
Is it possible to reference jmeter variable to properties file key?
and call variable in other place?
So far from debug sampler - looks like jmeter load UDV first and then jmeter properties not the way around.
All your tries are getting variables , you need to get property using different functions:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
In your case set my.var with the following value
${__P(var_from_prop_file)}
Or
${__property(var_from_prop_file)}
Similar result, just notice that __P have default value 1
The default value for the property. If omitted, the default is set to "1".
Another option is using JSR223 Sampler using vars to set variable and props to get property:
vars.put("my.var", props.get("var_from_prop_file"));
The fastest way to bulk convert JMeter Properties into JMeter Variables is using JSR223 Sampler and the following code:
SampleResult.setIgnore()
props.entrySet().each {entry ->
vars.putObject(entry.getKey(),entry.getValue())
}
Where:
SampleResult.setIgnore() - removes JSR223 Sampler from listeners and .jtl results file
props - shorthand for JMeter Properties (basically an instance of java.util.Properties)
vars - shorthand for the instance of JMeterVariables class

How do you mix JMeter command line args with Gui args?

I am trying to run a single recording in various different ways without copying the recorded pages.
I have created two Property File Readers that look for:
C:\performance\jmeter\users_${__P(ttype)}.properties
and
C:\performance\jmeter\${__P(env)}_${__P(region)}.properties
where the ${__P(xxx)} variables are passed on the command line as so:
-Jregion=UK -Jenv=dev -Jttype=isolated
These property files load the following variables (for example):
- usercount=25
- duration=1800
- host.name=server1
- host.port=8546
These are used in the HTTP Request Defaults:
${__P(host.name)}
${__P(host.port)}
and Thread Group:
${__P(duration)}
${__P(usercount)}
This works fine. However, if I want to run the same test in the Gui for a single thread (to check it works), these variables are not populated and the test fails.
I can create a User Defined Variable element but these have the format
${xxx}
so cannot be used interchangeably.
Is there any way to do what I'm trying to do here, please?
Option 1: you can pass the same parameters via '-J` arguments as JMeter in the GUI mode respects them as well
Option 2: you can specify your properties values in user.properties file (located in JMeter's "bin" folder) like
usercount=25
duration=1800
etc.
The properties values passed over the command-line will override those, which are specified in the user.properties
See Apache JMeter Properties Customization Guide for more information on using JMeter properties
By the way, you ain't gonna need this Property File Readers, there is a possibility to add extra properties files in JMeter via -q command line argument.
-q, --addprop
additional JMeter property file(s)
Discovered another way to resolve this issue.
The __P() function can take a second argument that acts as the default if the first value isn't resolved.
So
${__P(host.name)}
${__P(host.port)}
become
${__P(host.name,server1)}
${__P(host.port,1234)}
This works as well.

Resources