I have several JMeter test plans which should be executed in different environments, say Dev, Test, UAT, Live. In each test plan I would like to have a simple way to specify whi
I use a JSR223 sampler with Groovy to register new parameters. Make sure to put the JSR223 sampler in a Only Once Controller, so it is ran only once (per thread).
I have in the test plan all variables registered for all environments like this:
TEST.user = 123
TEST.url = test.mysite.com
LOAD.user = 435
LOAD.url = load.mysite.com
Then I specify which environment I want to select with a command line parameter at startup like: -Denvironment=TEST
My JSR223 script will add new variables to the test, without the TEST. prefix. In my scripts I just reference ${user}
This is the script to use:
JMeterVariables jmv = new JMeterVariables();
for (Map.Entry item : vars.entrySet()) {
if (item.getKey().startsWith(env)) {
String keyname = item.getKey().substring(env.length()+1);
String origval = vars.get(keyname);
if (origval==null || (origval.equals("") && !item.getValue().equals(""))) {
jmv.put(keyname, item.getValue());
}
}
}
if (!jmv.entrySet().isEmpty()) {
vars.putAll(jmv);
}