Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter environment specific configuration

Tags:

java

jmeter

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 which environment to use. Each environment has a lot of configuration such as hostname, port, ssl-cert, user name, password, account numbers and other test data.

One thing I'm trying to achieve is the ease of switching environments while using JMeter GUI or running scenarios from build scripts.

One of my ideas is to use the "Include Controller" to include another jmx file which has list of User Defined Variables and other config elements. However, JMeter does not support variables in the included file name, so I cannot parametrise the scenario by an environment name. Include Controller supports JMeter parameter "includecontroller.prefix", but it is not very flexible, e.g. I cannot change it from JMeter GUI, I should change JMeter config files and restart it.

I've tried to use Switch Controller, but no luck, it doesn't switch configuration elements, only samplers.

What is the best practice to externalise environment specific configuration from test scenarios and share it between several scenarios?

like image 709
kan Avatar asked Mar 19 '14 15:03

kan


2 Answers

If your are looking to make your life easy in the GUI only, an easy way is to duplicate your User Defined Variables for each environment and disable all others except the environment you are executing your tests against, something like the following:

enter image description here

like image 68
ama Avatar answered Sep 27 '22 19:09

ama


I would suggest to substitute all environment-specific variables or values with JMeter Properties. See following functions for reference:

  • __property()
  • __P()

For example you can define a property called hostname in either jmeter.properties file or as JMeter command line argument as follows

jmeter -Jhostname=169.140.130.120 -n -t yourscript.jmx -l yourscriptresults.jtl

and refer to in inside your script as:

  • ${__P(hostname,)} or
  • ${__property(hostname,,)}

See Apache JMeter Properties Customization Guide for more details.

like image 36
Dmitri T Avatar answered Sep 27 '22 20:09

Dmitri T