Jmeter threadNum function returns "StandardJMeterEngine" - jmeter

I am trying to use threadNum function in JMeter (2.13) but whenever I use it in "User Defined Variable" as ${__threadNum()}, it returns
"StandardJMeterEngine"
.
Isn't it supposed to return thread number??
Is this correct behavior?

The function is designed to be inlined in the test script, like:
See Using JMeter Functions - Part II guide for more information on this and other JMeter functions

Related

JMeter loop index always return 0 in Loop Controller

When I use the command ${__jm__myLoopControllerName__idx} in JSR223 Sampler, it always returns 0 as the index.
The sampler is in the Loop Controller. But I can see that the CSV file I'm looping is done for each line because in the listener "View Result Tree" I can see in the Request Headers, that the data is from each line. What am I doing wrong ?
Thanks for your help.
M.
Use vars to get variable in JSR223 script:
String index = vars.get("__jm__myLoopControllerName__idx");
variable inside ${} syntax is getting cached
ensure the script does not use any variable using ${varName} as caching would take only first value of ${varName}. Instead use : vars.get("varName")
As per JSR223 Sampler documentation:
The JSR223 test elements have a feature (compilation) that can significantly increase performance. To benefit from this feature:
Use Script files instead of inlining them. This will make JMeter compile them if this feature is available on ScriptEngine and cache them.
Or Use Script Text and check Cache compiled script if available property.>
When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.
So either put your ${__jm__myLoopControllerName__idx} to "Parameters" section and refer it as "Parameters" in your script:
or use vars shorthand for JMeterVariables class instance like:
vars.get('__jm__myLoopControllerName__idx')

Assigning value to the variable based on the request

I have created a jmeter script as below
I am using the user defined variable with function __P() and passing the Url from .sh file
My requirement is, if the url passed is "www.abc.com" then set the value of the variable ${Prefix} to "foo" else set it to "bar"
I tried using JSR223 PostProcessor, but JSR223 PostProcessor has to have a sample associated with it.
Any suggestion how do I achieve it?
Use the following __groovy() function in the HTTP Request sampler directly:
${__groovy(if (vars.get('Url') == 'www.abc.com') {return 'foo'} else {return 'bar'},Prefix)}
For subsequent requests (once the __groovy() function has been run) you will be able to use just ${Prefix}
More information: Apache Groovy - Why and How You Should Use It
If you're not too comfortable with Groovy scripting you can consider using __if() function, it's a part of Custom JMeter Functions bundle, can be installed usign JMeter Plugins Manager

jmeter beanshell call jmeter function

I have a HTTP request sampler configured. In the request body, I call out to a beanshell function I wrote:
${__BeanShell(createHeader("GET"\,"Customer"\,"${__UUID}"\,"${__time(yyyy-MM-dd'T'hh:mm:ss)}"))}
The function just builds some request strings with the passed-in parameters. I want to remove the jmeter function calls (__UUID and __time), and call them directly from within the beanshell function. I could not find a way to do that.
Thanks
Don't inline JMeter Functions or Variables into scripts, in your case you will have to go for code-based equivalents instead, to wit:
__UUID() -> UUID.randomUUID().toString()
__time() -> new java.text.SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss").format(new Date())
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting, in your case it would be __groovy() function. If you want to re-use createHeader method - you can put it into a separate .groovy file and define groovy.utilities property pointing to this file.
See Apache Groovy - Why and How You Should Use It article for more information on using Groovy scripting in JMeter tests.

JMeter - How to set a variable when all Test Plans Threads have passed

I wish to set a global variable indicating that all of my Threads have passed. Any help would be appreciated.
You can add a JSR223 Listener to your Test Plan and use the following code:
if (!prev.isSuccessful()) {
props.put('success', 'false')
}
If any request fails the code will set success property value to false, you can check its value using __P() function as ${__P(success)} where required.
prev stands for current SampleResult see the JavaDoc for all available functions and Apache Groovy - Why and How You Should Use It guide to learn what else you can do with Groovy scripting in JMeter

How do I call a Custom Function in JMeter

I've created a custom function in JMeter that returns a n length string with random characters. Where should I define the function, and how do I call it?
As long as your function is in the jmeter classpath, you should be able to call it just like any standard function with ${...} syntax, as described here.
Do make sure your jar file containing your function is in lib/ext, or added to the jmeter classpath via search_path's input option
You can do this in a beanshell script or via a javascript call. See the manual on
functions and on the beanshell preprocessor.

Resources