Jmeter - Trigger if condition via Command line value - jmeter

Using JMeter I would like to execute a script where the script is entering into specific condition based on the property provided via windows CMD execution. My script looks like:
and execution is done via CMD as:
jmeter -n -t C:\Users\test\Documents\api.jmx -Jusers=1
How can I enter into just single specific If controller, based on the value provided on the runtime?

I think you should rather go for a single Switch Controller instead of 3 If Controllers and use __P() function to read the value from the command line:
${__P(scenario,)}
This way if you execute JMeter as:
jmeter -Jscenario=A -Jusers=1 -n -t C:\Users\test\Documents\api.jmx
it will run Sampler (or a Logic Controller) named A, similarly for B and C
You may also find Running JMeter Samplers with Defined Percentage Probability article useful.

Add check to users parameter for each If, in your case:
${__groovy(props.get("users")=="1")}
Checking this and using __jexl3 or __groovy function in Condition is advised for performances

Related

how to pass arguments to shell script in Jmeter OS sampler generator

I want to pass arguments to shell script in Jmeter - OS sampler processor
My shell script - move.sh:
#!bin/bash
source="$1"
dest="$2"
cp $source/*.txt $dest/
I run this as
sh move.sh t1 t1
This will copy data from t1 directory to t2 directory.
Now I want to integrate with JMeter
Below is my setting
[Jmeter image][1]
[1]: https://i.stack.imgur.com/RfEEx.png
Here I am not getting error in execution but files are not getting copied from t1 to t2 directory
First line of your script is wrong, it needs to look like:
#!/bin/bash
See Bash Shebang for more details
Your OS Process Sampler configuration is incorrect, you need to use -c as the first parameter.
If JMeter doesn't behave as you expect it to behave first thing you should check is jmeter.log file. If you don't see anything suspicious - increase JMeter logging level to something more verbose.

JMeter - Running preprocessor when called from command line?

I'm very new to JMeter.
My team has existing JMeter Test Plans that we generally run through the GUI. I am experimenting with running it from the command line.
In our test plans, we have a bunch of variables declared at the TestPlan level. These variables contain information for setting up different environments (eg test, prod, dev). Directly under the TestPlan is a JSR223 PreProcessor that basically takes the variable that shows what environment you're trying to run in and sets up the hostname, port, etc to the values for that environment.
When I run the test using the GUI, it works perfectly under the selected environment. However, when I run it with the command line using the following command:
jmeter -n -t testName.jmx -l Results.csv
it tries to run under the defaulted environment and doesn't change it to the environment I want. I tried adding a -Jenv=dev, but that didn't seem to make any difference.
Do preprocessors not run when called from the command line? Could there be something else that I'm missing? Given my inexperience here, I'm not even really sure how I can tell what the problem is.
Thanks so much!
It is very difficult to conclude what is the exact problem in your jmeter script. Looking into the problem statement I can sense that you need to find correct way of passing a variable from command line and processing it in a script.
Example of passing a variable from command line and handling it in jmeter is shown below:
Declare a variable with value as a property in jmeter. You can use anything here, I have used User Defined variable. Variable env is declared as ${__P(env)}
Using JSR to process that variable. Here just printing the value passed from parameter into jmeter log. Now the value can be reused using ${env} variable [note it is a variable and not a property, because we declared that way in User Defined variable].
String valuePassed = vars.get("env");
log.info("Parameter passed from command line: " + valuePassed);
Run from the Command Line using following command:
jmeter -n -t <>.jmx -Jenv=Prod -j sample.log
Result shown in log file
PreProcessors are executed only in conjunction with Samplers
If you don't have any Sampler in your Thread Group - none of PreProcessors will be executed.
Also be aware that PreProcessors obey JMeter Scoping Rules to wit:
if you have a PreProcessor added as a child of the Sampler - the PreProcessor will be executed before the given Sampler
if you have 2 Samplers and a PreProcessor at the same level - the PreProcessor will be executed before each Sampler

run jmeter in non gui mode, sending parameters for a groovy script, howto?

My testplan uses a JSR223 PreProcessor, which invokes a .groovy script with a parameter.
In GUI mode this parameter can be set in section "Parameters to be passed to script".
How can I define/set the value (the parameter) when jmeter runs in non-gui mode?
Can't find anything on that in the documentation!
It is the same plan that run in GUI and NON GUI mode.
So you can use the same mechanism.
To pass the value from command line:
-JpropName=value
To get it, use __P function:
${__P(propName)}

How to replace jmeter keys when running Taurus

Problem:
I am currently hard coding a password in my jmeter .jmx test file.
I want to be able to either set this in the config.yaml or on the command line using something like a "-o modules.jmeter.properties" switch (to replace this in the CI pipeline)
However I cant get either of these to actually replace the value in the .jmx file.
I have looked through the Taurus doco and ended up trying the following.
Updating the config.yaml file:
execution:
- executor: jmeter
scenario:
script: ../scripts/apigee_loadtesting.jmx
data-sources:
- ../datafiles/
concurrency: 2
ramp-up: 30s
hold-for: 1m
steps: 2
modules:
jmeter:
properties:
es.password: P#ssw0rd!
Also tried this from the commandline:
bzt ../config.yaml -o modules.jmeter.path=/usr/local/apache-jmeter-4.0.2/bin/jmeter \
-o modules.jmeter.properties.espassword=P#ssw0rd! config.yaml
But neither of them seem to do anything meaning, Any suggestions would be appreciated
Taurus itself will not change anything in the .jmx script, just make sure that you refer the property using __P() function as ${__P(es.password,)} in the .jmx script and the value will be substituted with the one from .jmx file or command-line override.
I would avoid using dots in properties names as it might cause problems with overriding properties values from the command-line. So stick to espassword everywhere if possible
The change your command line so config.yaml would be the last argument like:
bzt -o modules.jmeter.path=/usr/local/apache-jmeter-4.0.2/bin/jmeter -o modules.jmeter.properties.espassword=P#ssw0rd! config.yaml
See Navigating your First Steps Using Taurus article for more information on running JMeter tests using Taurus

Calling two functions in Windows batch file one after the other

I have two scripts which are to be executed and i am using Windows batch script for automating of running the scripts.
I have to read 10 user input values and then run the two scripts using those parameters.
I am successful in executing the first script and failing with the second script.
Issue is that the cmd prompt exits after completing the first script.
How to make cmd prompt run the second script as well using the input parameters.
Any Help on this??
Thanks in Advance.
You have two options to execute a batch script from you code. It's either START or CALL:
START will execute your code in it's own variable scope, means the variables you've set in the first script won't be available. Further both scripts will be executed in parallel and not one after another (unless you use START /WAIT).
CALL on the other hand will do exactly what you need. It will start the first script in the same scope (previously set variables are variable), execute it and afterwards it will run the second sript (also in the same scope).
TL;DR this will work:
...
CALL BatchScript1.bat
CALL BatchScript2.bat
...
If you call scripts from another script you have to use the call command:
#echo off
call first.cmd
call second.bat
echo Here I'm back again !

Resources