I have some user defined variables:
SERVER_NAME myhost.com
THE_HTTP_PROTOCOL HTTP
LOOP_COUNT 2
Then, I use a Recording Controller to capture my browser actions. Unfortunately, JMeter does more variable substitution than I'd like it to. For example, it substitutes ${LOOP_COUNT} into a web site name that contains "2", e.g., /host${LOOP_COUNT}/somePage. My favorite example of over-zealous variable substitution is my ${THE_${THE_HTTP_PROTOCOL}_PROTOCOL} Header Manager.
Is it possible to make the recording more selective about what variables can be used for substitution? For example, of the variables I've listed, I'd really only like SERVER_NAME to be substituted in.
I'm using JMeter 2.11.
For now you must disable User Defined Properties during recording.
Maybe you could open a bugzilla request here:
http://jmeter.apache.org/issues.html
Note that variable substitution works better with Regex Matching checked (HTTP(S) Test Script Recorder component) as it will be much more intelligent.
But ensure if you use it you do not use values (usually short ones) that can be frequently in responses/requests.
I wouldn't recommend to substitute variables during recording as the behavior may be flaky.
If you want to parametrize your recorded test it's better to go for
HTTP Request Defaults - for host, protocol and any other http-related stuff
JMeter Properties and functions like _P() or _property() to retrieve them .
Actually I would set host and protocol as properties too as they can be set via command line, via Ant or Maven plugin or any other way of invoking JMeter. Besides properties can be shared across thread groups and variables have local scope.
I was able to work around the problem by adding a User Defined Variables (UDV) element to my workbench.
It defined:
THE_HTTP_PROTOCOL someStringThatShouldNeverBeMatched
USER_COUNT someStringThatShouldNeverBeMatched
Then, when I recorded, I did not get the unwanted variable substitutions.
Another option is to break up a monolithic collection of variables into smaller groups using User Defined Variables. Then, you can disable certain of those smaller groupings when you need to record. For example, you could put USER_COUNT into a "Flow of Control" UDV, and then disable it at recording time as shown below.
Related
How to log regular expression extractor value in results when ran through blaze-meter
If you're a BlazeMeter customer it could make more sense to contact BlazeMeter Support, most probably you will get more quick and professional response than trying to ask random people over the Internet for their opinions.
Whatever. What do you mean by "log"?
If you need to write the value to jmeter.log file - just add __logn() function somewhere in your script like:
${__logn(My variable value is: ${foo},,)}
replace ${foo} with your actual variable name
Once test finishes you will see the variable value in the jmeter.log file (you can download it as a part of artifacts.zip bundle from your test Execution Logs
If you want to track the variable value per each sampler - the easiest option is to configure Sample Variables property and provide your variable value there:
this way you will see an extra column in the kpi.jtl file containing your variable value
Artifacts view containing kpi.jtl and jmeter.log files
I'm trying to set a variable as a parameter value in a Backend Listener. I tried to add the variable as
${"testname"}
and also as
$["testname"]
but both options didn't work. JMeter consider them as a string and not as a variable. Any ideas how I can do that ?
The correct syntax for JMeter Variables is ${variable_name_here} so you need to change it to ${testname} and it should start working as expected.
If there will still be problems make sure that the variable is defined and has its respective value, it can be done using Debug Sampler and View Results Tree listener combination
P.S. Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting instead of Beanshell (and in fact any other languages) so while your script is relatively small maybe it's a good time for migration.
At the moment, my JMeter test uses a CSV Data Set Config to iterate through a limited set of input data for each HTTP request that I do.
But I don't want to deal with the hassle of an external file (uploading it to my test runner, etc.) - I'd like to just embed the data into the jmx file itself.
I was hoping for something like a "test data" node, that would work similarly to a CSV data set (with Recycle on EOF especially) and I'd just copy/paste the data into the test plan instead of working with an external file.
I'm thinking I might be able to work around it with a JSR223 preprocessor - but is there a better built-in way?
Edit: As per comment: the data cannot be generated.
If you want to do this via JSR223 Test Elements and Groovy language correct syntax would be
vars.put("messageId", "wibble");
vars is a shorthand for JMeterVariables class instance, see the JavaDoc for available functions and properties.
Easier way would be going for User Defined Variables or User Parameters or even better Set Variables Action
You can create a text contains keys and values separated with tab, copy all text
Notice if you have property file you can replace = with tab
Add to JMeter GUI User Defined Variables and click Add from Clipboard
It'll load all your variables to JMeter without "do that by hand using JMeter's GUI"
.
This is my first go at a script based approach using a JSR223 preprocessor node:
// This is where the data is embedded. Up to a couple of hundred entries
// is probably fine, more than that will likely be a bad idea.
def messageIdList = ["graffle", "wibble", "wobble", "flobble", "gibble", ...]
def messageIndex = (vars.getIteration() -1) % (messageIdList.size() -1)
println "iteration ${vars.iteration}, size ${messageIdList.size()}, index: ${messageIndex}"
vars.put("messageId", messageIdList[messageIndex]);
messageIndex++
This appears to do what I want, even when run in a Thread Group with multiple threads.
I'm not sure exactly what the vars.getIteration() represents, and I'm not clear about the precise lifetime / scope of the variables. But it'll do for now.
Any better answers will cheerfully accepted, marked and upvoted.
I am using the latest version of TeamCity and I am trying to make a parameter specification that refers to parameters.
I tried making a select (combobox), where the options of the checkbox are referring to variables. This should be possible, as there is a "parameter" icon to the right of the box suggesting me that I can use parameters here.
The full setup is shown below.
However, when I want to run the build, the only options are literally %foo% and %bar% as if the parameters have not even been evaluated.
Instead I had expected the options to contain the values of the variables that they are pointing to.
What am I doing wrong here?
Might be a bit late, but this is how I did it:
I have a few parameters for holding passwords, e.g. 'mfgpwd'
And I refer to these in another parameter using the syntax:
mfgpwd=%system.mfgpwd%
(I'm using TeamCity 8.1.5)
I need to load test a service I've developed but I need the data that I post to the web service to have some variance.
I've set up Thread with an Http Request and I've the parameter I need to set but I can't see how I'd go about changing the contents of the HTTP parameter from request to request.
Ideally I'd like to feed in a list of data Items and have JMeter iterate through them.
Prepare kind of csv-file with list of your test-params and use it to parametrize your test-samplers, using at least the following:
CSV Data Set Config
Explained example here, simple example here.
Jmeter functions: __CSVRead, __StringFromFile.
Variables From CSV sampler from jmeter-plugins.
One way would be to prepare a CSV file with all the values that you will need. There are a multitude of different ways to use it afterwards. Alies Belik's answer listed most of them. The drawback of the CSV approach, however, is that you need to generate the list of values, and in some tests you can't simply reuse it without cleaning up/reinitializing the back-end database.
Another option are the functions for generating random values, usually paired with "User Defined Variables" controller.
__Random for generating numbers in a given range.
__RandomString for generating random strings of a given length and containing a set of characters.
This is a powerful mechanism, but I find it somewhat cumbersome and clunky.
For simple variables, like generating username/password/e-mail combinations, I prefer and find it easier to use the Random Variable config element. It's available since Jmeter 2.3.3. You add it to your thread group and specify a variable to store the random value for each thread. You can later reference this variable in your HTTP sampler, in the GET/POST parameters of the request, by specifying the Value of the parameter to be testuser-${rnd} for username, testpass-${rnd} for password. Each thread will get a different value of ${rnd} so there is a small chance (but there is still a chance) that you will get duplicate values (users).
Besides the functions mentioned in #zorlem answer, You can also use:
__UUID for generating a pseudo random type 4 Universally Unique IDentifier, if you need to generate random & unique strings.