In JMeter 5.3, variables do not work in functions [duplicate] - groovy

This question already has an answer here:
JMeter - submit JMeter function inside a script (JSR223 element)
(1 answer)
Closed 1 year ago.
I use groovy to write a script. In the screenshot, No. 1 works, No. 2 doesn't work, No. 3 works. It's normal to print No. 1 separately. No. 2 and No. 3 are written in a custom function. The parameter passed in by No. 2 is still ${re} instead of value

Don't inline JMeter Functions or Variables into Groovy scripts, your "No 1" and "No 3" work because they're GStrings and your "No 2" conflicts with JMeter Functions and/or Variables syntax.
So I would recommend moving your function into "Parameters" tab like:
Also according to JSR223 Sampler documentation:
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 if your ${secretKey} variable changes from iteration to iteration only first value will be used and this may ruin your test so you might want to change it to vars.get('secretKey') expression
Also be aware that according to 9 Easy Solutions for a JMeter Load Test “Out of Memory” Failure article you should always be using the latest version of JMeter so consider upgrading to JMeter 5.4.1 (or whatever is the latest stable version available at JMeter Downloads page) on next available opportunity.

Related

Store custom Groovy function in JMeter UI

Been struggling with this a lot lately: How do I store a custom Groovy script with imports etc in the JMeter UI so I can reuse it later?
I don't want to alter JMeter startup property files in any way
I want to be able to call this Groovy 20+ times within the JMX with different parameters
From the JMeter doc:
Once the script is working properly, it can be stored as a variable on
the Test Plan. The script variable can then be used to create the
function call.
The groovy (compatible with Beanshell) is 62 lines and includes imports of custom JAR files. If I could store this as a var callable with __groovy(param) that would be great, I don't see how to do that from the docs. Setting up 20 JSR223s is incredibly clunky but I am coming up with workarounds if there is no JMeter way to do this.
References:
https://jmeter.apache.org/usermanual/best-practices.html#developing_scripts
Depending on what you're trying to achieve:
There is a possibility to specify a path to the file with your code in any of JSR223 Test Elements so you won't have to copy and paste it multiple times into "Script" area so in case of changes you will need to amend it in one place only:
There is groovy.utilities property where you can specify the path to your .groovy file containing the logic callable from the __groovy() function, it defaults to bin/utility.groovy
You can compile your code to .jar file and store it under JMeter Classpath, this way you will be able to call your functions from any place. See How to Reuse Your JMeter Code with JAR Files and Save Time article for example implementation/usage details

Setting variables from Mule 4 Script (Groovy)

Previously in Mule 3.x.x, we would be able to set variables from within a groovy script using. message.setInvocationProperty("name", "value").
I cannot seem find a way to do this anymore. I am aware that the mule message structure has changed, but is there a way for one to set variables/attributes from a Mule 4 script similar to the way we could in Mule 3?
Thanks in advance.
No, in Mule 4 you cannot modify vars directly.
You can set the return value of the script to go directly to a variable though using the target attribute, with it's value being the name of the variable:
<scripting:execute engine="groovy" target="myVar">
Probably best as well - to keep the script decoupled from mule specifics.

Jenkins Extended Choice Parameter Plugin Groovy Script

So in the website for the plugin, the change-log for Version 0.61 (Mar 30, 2016) mentions that they have exposed Jenkins and project bindings for use in a groovy script. I'm currently trying to set a parameter (multi select) and i want it to have different options based on the value of another parameter which is set before this one in the Jenkins job. However i'm not able to get the value of that other parameter in the script.
My problem is very similar to the one explained here
I've tried using ${param}, $(param), $param, bindings.variables.get('param') in the script, and none of it works
I've also tried to set that parameter in the Variable bindings section of the script but still no success.
Any ideas about the correct way to obtain the value?
I set the variable binding as param on the other field that you want to dynamically populate and used param (please note that i didnt use $ ${} or binding.get etc). It worked for me.
As a side note, Will active choice reactive parameter work in your case?

Can I use Groovy scripts in SoapUI to enable/disable assertions?

I'm using SoapUI Pro and a DataSource/DataSink loop to test a web service.
To make life more fun, I need to pull from four distinct source files, all of which will cause different expected results.
I'd really like to do this in a single test loop, because having scripts with multiple loops tends to crash SoapUI more often than not, but the sticking point is assertions.
How can I enable or disable assertions in a Groovy script in SoapUI? GetData doesn't give me anything to hook onto, and a documentation dive did not reveal the proper syntax. I'd assume something like testCase.assertion, but there's no such property as "assertion" on testCase.
Alternately, can I use a Groovy script to change the assertion's content? In other words, if I want phrase X with file 1, phrase Y with file 2, I'm just as happy using the same assertion, so long as I can change the content it's trying to match.
You could use your Groovy script to set some kind of property testCase.setPropertyValue('expected', 'value'), based on which file you are reading. You could then use property expansion ${testCase#expected#} in the assertion content.

JMeter howto: same thread group - same variable - different value

I'm doing a performance test on different versions of my application.
The results end up in a csv summary-report.
Is there a way to change the variable correctly for each thread group?
Manual Script:
Script with variable: (not working, help needed).
I don't want to change the version manually when a version changes, but only one parameter. Thanks!
Try using _P or _property function in your Thread Group and Sampler names.
Like Application-${__P(version1,)}, Login-${__P(version1,)}, etc.
Provide property value via 'user.properties' file or via -J command-line argument as
jmeter -Jversion1=1.0 -Jversion2=2.0 -n -t path_to_your_script.jmx -l path_to_results.jtl
All generated reports will contain these properties.
References:
How do I run JMeter in non-gui mode
Apache JMeter Properties Customization Guide

Resources