An Introduction to JMeter Part-3
Lesson 3: Variables, Properties & Functions
Requirements: dummpy sampler plugin should be installed.
JMeter has few type of variables which are:
User defined variables
User parameters.
Functions
Variables define in the BeanShell scirpt.
jmeter variables can only be set within the test plan.
JMeter has three types of properties which are:
System properties
Jmeter properties
User properties
Properties can be set inside or outside the test plan.
User defined variables: is can be define in two places.
First approach sit can be define in test plan configuration screen user define variables.
Second approach the user define variables can be define in config element, reason of the second approach make more sense when we create scope rules.
-----------------------------------------------------------------------------------------------
Let us create a test script following the first approach click add name it testserverurl and initialize it with some value e.g. www.example.com as you can see in the screenshot.
Now let us add a thread group and under teh thread group add dummy sampler. In the response data add the variable you set, in jmetet variable start with $ sign and contain curly brases {}
${testserverurl}
Now add the listener view tree and save the file.
Now run it.
Here you can see in the response data is www.example.com, so the variable you put in there was expanded and output as a response for the dummy sampler.
Let's add the user define variable in config element, you can open it by right click on test plan > add > config element > user define variables
Now click add and we put in the variable name testvar and give it a value testvar0
Now let refer the variable name in response data in the dummy sampler UDV ${testvar}
Let's go save it and run it, here you can see variable define in the test plan are kind of a global variable. they can be used every where in the script.
The advantage of user define variables that they provide one place to set a constant value that all threads will use. There are cases when you want a separate value for each thread that's the used cased for user parameter
Let us take a closer look, right click on thread group and add pre processor and choose user parameter
This panel allows you to specify a series of values for any user variable, for each thread the variable will be assign from one of the value series and sequence. if there more threads and values get reused, for example lets add two different variables to the user parameter.
First I will click on add variable button then i click on add user button, now have 2 users up there.
Specify variable name UPvar
Now I will use the function helper dailoge to built a function the jmeter random number for each of this value
Select Random from choose function
The minimum value allowed for a range values 1
The maximum value allowed for a range values 100
Click generate and copy pasted in each of the value
In the Dummy Sampler request data add
${UPvar}
Let's take a closer look on user parameter the option Update Once Per Iteration
Update Once Per Iteration this actually controls how often values are updated, if you leave the check box unchecked then the parameters updated every sampler request made within the scope. any time it's red it's get updated.
If you checked the Update Once Per Iteration box the vaules will only updated once per iteration of that thread group.
Let's add another dummpy sample to see in practice, let's take the request data field and put same variables defined in user parameters in dummpy sampler.
${UPvar}
Save it
Let's clean up the view results and run it twice.
Now you can see in view result tree that each of the time the number if different.
Now let's checked Update Once Per Iteration in User parameters and run the test again.
Clear the results again and run test now you see two different samplers has same value.
In the second results value same but different from the first results
What happen is the value only updated when it went to the thread group the second time.
Let's talk more about jmeter function little more detail now.
we use the jmeter function the random function in our demo scirpts, jmeter function are operations perform on variable and constant.
The function result is a value that can be passed to any element of jmeter test plan.
Properties
They are global and can be defined outside the test plan. Properties control various aspect of the behavior of jmeter, can be access manipulated by the elements of your test plan.
System properties
Let's pronunce system properties is by adding sampler the debug sampler and then we configure it to just pronunce system properties.
System properties to True and false on Jmeter properties and User properties
Run it.
In view result tree on debug sampler response data you can see all the properties
You can edit the system properties file present in the jmeter install directory as per your requirement.
You also edit the following properties files as per your requirement.
Jmeter properties
User properties
In the next part we will learn Config Elements, Scoping & Logging
.