JMeter environment specific configuration

后端 未结 8 654
时光取名叫无心
时光取名叫无心 2021-02-04 13:05

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

8条回答
  •  被撕碎了的回忆
    2021-02-04 13:35

    Like the Manish Sapariya mentioned, Parametrized Controller is quite useful to prepare configuration for more than one environment. I used it in the previous place I worked and started the configuration now in new place. It is a bit of work at the beginning, but later it is easy in maintenance. There is a bit of tutorial in the link that is provided above, but it won't take in consideration that you want to run just one env at a time. I will describe it a bit below, maybe it will be useful. So, slowly step by step: Env Profiler

    1. First of all - you need two thread groups - one for environment profiles (no 1 on the first screenshot - Env Profiler) and one for your test cases, included test plans etc. (no 2 - API Requests). The latter has to be disabled as it is container that should not be executed straight from here (right click -> disable or Ctrl+T)
    2. Then you need your User Defined Variables elements (no 3) - I'm using three of them:
      • first for defining which environment will be executed (environmentType var) and logins/passwords, tokens etc.
      • second with IDs for items needed for tests
      • third with IPs, ports, path prefixes and so on.

    The most important thing here is that I have them separated at this moment by prefixes in variable names, so in one UDV element I have variables like dev.serverIP, dev.serverPort, preprod.serverIP and so on (second screenshot) populated with values relevant for that environment. Additionally in one of this UDVs I have environmentType variable (mentioned earlier) with default value 'dev' (which you can change manually here or provide different value when launching through command line/CI or whatever)

    UDVs

    1. Now in the Env Profiler I have If Controllers(no 4 on the first screenshot). For dev env I have (no 5 on the first screen):

      "${environmentType}" == "dev"

    For each env (if controller) you have to provide proper condition like this above.

    1. Each IfController contains that "jp@gc - Parametrized Controller" mentioned before (that you can download as part of Extras Set here by the way). In each Param Controller you assign to variables that you use in test plans variables specific for that environment, e.g. name: serverIP, value: ${dev.serverIP} for dev env (third screenshot)

    Parametrized Controller

    1. And now the last thing - tests and plans you want to execute.
      • In that disabled Thread Group (API Requests) you add Simple Controllers that contains your tests or Include Controllers that import some tests from other files.
      • When you have those tests, for each one that you want to run in that particular environment you have to add Module cotroller inside Parametrized Controller with path to that test (screenshot below)

    Module Controller

    And that it is pretty much it. Now maintaining:

    • to add new variable you have to add it in UDV with prefixes (dev.newVar, preprod.newVar) and fill the relevant values, then add proper entry in Parametrized controllers (those newVar = ${dev.newVar}) and that's it
    • to add new test from other Test Plan - add Include controller with path to that file and add Module controller in each Paramterized controller directing them to that Include Controller
    • to add new environment just copy the one you already have, change its If contr., Parametrized controller and fill values in UDVs The nice thing here is that if you want, lets say, dev env with all tests and the other with just some somke tests you can prepare a copy, change If controller to take some other value of env variable (like dev for all tests, devsmoke for smoke tests) and add or delete some of the module controllers in that new profile. Of course you can build it up a bit and you can ues different threads for different parts of the system for easier maintanance, just do not forget to disable those threads working as containers.

    I know it's a lot to do when you start, but it is not so bad later, when just adding some stuff - probably the easiest way to do it anyway.

提交回复
热议问题