Monday 17 November 2014

User Defined Variables in Jmeter



User Defined Variables in Jmeter
The User Defined Variables element lets you define an initial set of variables. All the UDV elements in a test plan - no matter where they are - are processed at the start. 
It is a type of config element and you can change the values in 1 place in the test plan.
The syntax for referencing a variable in JMeter is ${VARIABLE_NAME}
Objective: To use user defined variables in Jmeter.
Benefits:

     1)       In case we have to run the same test on multiple environments, we can specify user defined values and enable/disable according to Testing needs.
    2)      User Defined values (UDV) can be easily used for parameterization.
    3)      You can add a user defined variables config element to the top of the test plan and put all the settings in there I'd like to tweak. For example, URL's, timeouts, etc. All in one place at the top of the script. This makes it easy to tune scripts, e.g. to test different pages, to tweak the number of users, etc.


Steps:
      1 .       Create a Test plan, right-click on Thread Group > Add > Config Element > User Defined Variables.

 


    2.       Now add the parameters that will be used in your application which is to be recorded by jmeter.  Here the variables are username and password and provide their values as well. The column “Name” represents the name of the variable and column “Value” represents value to be used in the application.

   3.       Now record the script in Jmeter.

   4.       After recording observe how Jmeter has replaced the variables values by the syntax as shown below.



    The values for user name and password are replaced by syntax  ${VARIABLE_NAME}.
  
    Variable name/value pairs. The string under the "Name" column is what you'll need to place inside the brackets in ${...} constructs to use the variables later on. The whole ${...} will then be replaced by the string in the "Value" column.


      Disadvantages of User Defined variables:
    1)      UDVs should not be used with functions that generate different results each time they are called. Only the result of the first function call will be saved in the variable. 
    2)      UDVs cannot be used for run time execution of variables.
    3)      If a runtime element such as a User Parameters Pre-Processor or Regular Expression Extractor defines a variable with the same name as one of the UDV variables, then this will replace the initial value, Best Practice is always use different names for different elements in Test plan.





 



 


No comments:

Post a Comment