How to run environment based execution using same set of script in jmeter - jmeter

I need to run same script in different environments like QC, UAT and PROD. I would like to know how do we configure and run based on specified environments.
Note - I tried with properties file but it requires some manual effort which we do not want.
Please help with some examples

If environments don't change you can create 3 separate HTTP Request Defaults configuration elements containing protocol/host/port/path/etc. settings for different environments and depending on the target environment you can toggle this or that HTTP Request Defaults element.
If you need unattended way of enabling/disabling HTTP Requests Defaults (or any other test element) you can consider using Taurus tool as a wrapper, it provides syntax to enable/disable any JMeter test element via YAML config or via command-line arguments.

Related

How to pass properties files to Jmeter server in distributed setup

I have Jmeter distributed setup (One client and one server).
In single jmeter instance I'm using the below command to execute jmeter with a properties file that will pass the user defined variables to my test script
/apache-jmeter-5.3/bin/jmeter -p reco.properties -n -t Performance.jmx -l test2server.csv
When I tried to use the same command including the server configurations I noticed that the values defined in my "reco.properties" are not picked at the test execution.
Instead I need to pass all the variables with "-G" argument. Ex:
/apache-jmeter-5.3/bin/jmeter -GENV=test -n -t Performance.jmx -l test2server.csv
is it possible that I can pass all variables in a properties file for Jmeter Server as I do in the normal execution with "-p"?
Thank you
As per JMeter Documentation:
If the test uses any data files, note that these are not sent across by the client so make sure that these are available in the appropriate directory on each server. If necessary you can define different values for properties by editing the user.properties or system.properties files on each server.
So currently as per JMeter 5.4 this is not supported, you either need to pass the properties one-by-one like -Gprop1=value1 -Gprop2=value2 or to copy the .properties file to all the slave machines
The limitation can be also worked around via getting the properties from a dataabse using JDBC Request sampler or with plugins like HTTP Simple Table Server or Redis Data Set
If you do believe that the feature is essential you can try raising an enhancement request in JMeter Bugzilla

JMeter - Execute specific components only on GUI and not CLI

I add several components for debugging as Debug Sampler, View Results Tree and JSR223 Sampler that are useful in GUI mode, but I want it to be ignored when running load test,
Is there such option of executing Sampler/Listener only in GUI mode and not in command line/"load" mode?
I am not sure that this is the exact answer you are looking for but still let me try. We know that JMeter script is nothing but xml in disguise and structure look like this.
So for every Jmeter component, there is enable property which needs to be true so that it will get executed as part of JMeter Test plan. Now if we can change this some properties which can be passed as parameter then we can make them disable at the run time.
Change in jmx will be reflected like this...
If you run this script in Non GUI mode with additional property passed as parameter, we essentially achieve what we want.
jmeter -n -t .\ExcludeJMeterComponent.jmx -l result.CSV -e -o "Output" -DenabledDebugComponents=false
Issue with this approach is, if you load this script again in JMeter, these values, manually edited jmx going to go away/get override with your next save but if you are using any version control system to keep track of your jmx script [which you must be doing] it will be very easy to add this changes in the script again in no time.
I will post this with more details once my blog is set up.
Found a workaround, to send in CLI JMeter property as -JignoreFirstSampler
Add If Controller as a parent of samplers to exclude checking if property is defined
${__isPropDefined(ignoreFirstSampler)}
The __isPropDefined function returns true if property exists or false if not.

Jmeter Cross-Platform Path config issue

I am working on master-slave Jmeter configuration, my data set exist on each machine on a different path for (macOS, Windows).
I use a global data set to fetch data for multiple thread groups.
However, the variable/property can be different across platforms.
I also tried the JSR223 to check the, but still no luck. check out the below snapshot.
I am trying to make sure that once I ran my test from Master (Mac), it also run on Windows.
Any thoughts how to do that on multiple platform setup.
The best solution is placing your test data under the same path which will be relative to JMeter working directory, this way you will not have to change anything in your script.
If for some reason you cannot afford this you can add a JSR223 Sampler to your Test Plan and use the code like:
if (org.apache.commons.lang3.StringUtils.containsIgnoreCase(System.getProperty('os.name'), 'Windows')) {
vars.put('data-path', 'c:/windows/specific/path')
} else {
vars.put('data-path', '/macos/specific/path')
}
It will detect the operating system name in the runtime and you will be able to define an OS-specific paths using the above approach.
vars is a shorthand for JMeterVariables class instance, the above code defines ${data-path} JMeter Variable which you can use later on for specifying data files locations. See Top 8 JMeter Java Classes You Should Be Using with Groovy to learn more about JMeter API shortcuts exposed to JSR223 Test Elements

jmeter distributed testing slaves not reading the property when properties are sent with -G option

I am able to successfully run JMeter in master slave configuration in both GUI and non GUI mode when the user defined variables are hardcoded in the test plan. But now I am trying to set these with properties using the
-Gglobal.properties option on master where I have the properties defined in the global.properties file.
Then I am using ${__property(concurrent.threads)} function in the User defined variables.
When I run the remote test I see the property being set to the literal "concurrent.threads" and the test fails to run. The jmeter manual for __property reads:
If the property value cannot be found, and no default has been supplied, it returns the property name
why are the properties not being sent to the slaves, is there a bug in JMeter?
I also tried -Gconcurrent.threads=100 in the command line options and I still get the same behaviour.
Looks like it worked for some other user in 2015 --
How to configure the number of threads to run on slave machines in Jmeter?

JMeter - Bandwidth control not working

I'm attempting to run a testplan using different qualities of network.
To accomplish this I set a "HTTP Request Default" so they all use HTTP 3.1 or 4.
Then I passed the properties as follows:
-Jhttpclient.socket.http.cps=21888 -Jhttpclient.socket.https.cps=21888
However it doesn't seem like it's doing much, do I need to enable the setting in the user.properties as well (to maybe 0) which I can then overwrite with the property?
I am doing this with a distributed test plan (multiple load generators in non-gui mode) but since they are all started through the one "master" node I would think they would all take the property.
You need to start all the slaves using these -J command-line arguments or modify user.properties file on each slave in order to make it work.
Properties are not being automatically passed to slaves from the master node. You can also try out -G key, as per Full list of command-line options
-G, --globalproperty <argument>=<value>
Define Global properties (sent to servers)
e.g. -Gport=123
or -Gglobal.properties
Also remember that all slaves are quite independent so each of them will have 21888 characters per second throttling so cumulative bandwidth will be sum of all slaves.
See How to Simulate Different Network Speeds in Your JMeter Load Test article for more information on simulating different networks during JMeter test.

Resources