In JMeter, I have added a Config Element of User Defined Variables to state my variable data. However, I see I can do the same thing up in the main Test Plan element.
When should you define your variables within the Test Plan and when should you define them within the Config Element? What's the pro/con of each?
Thanks.
They are the same. Take a look at User Defined Variables description:
The User Defined Variables element lets you define an initial set of variables, just as in the Test Plan
But using separate config elements makes sense for 2 reasons:
Script organization. For example if you have many variables, instead of dumping them all in main Test Plan element, you could define several config elements with the name that suggests what kind of variables they store.
Ability to use variables defined in previous User Defined Variables elements. According to the same reference:
UDVs are processed in the order they appear in the Plan, from top to bottom. <...> the variables are not available for use until after the element has been processed, so you cannot reference variables that are defined in the same element. You can reference variables defined in earlier UDVs or on the Test Plan.
So having several elements provides you with an ability to use previously defined variables in the further ones. One of the use cases is, for instance, definition of some reusable function(s) in one User Defined Variables element, and using them in the following User Defined Variables elements.
Related
I'm trying to define fragment inputs, which are variables that should be defined to have the fragment execute successfully (I'm trying to achieve something similar to method arguments in programming languages)
I have tried to use test plan variables in the fragment like so :
But when the fragment is included in another test plan and with looking to the Debug PostProcessor output, those variables are completely ignored.
Please is there official JMeter documentation that mention test plan variables are ignored in this case ?
What is the cleanest way to define variables for a fragment with a scope local to the fragment or at least local to current thread ? My purpose to make a fragment clearly defined what are the variable it uses, so it can be easily reused by other developers
Thank you
If you need to declare the variables to be used in the test fragment - go for User Defined Variables configuration element like:
When you call a Test Fragment from a separate Test Plan the variables defined in that Test Plan will be available for usage.
Alternative option is using JMeter Properties which are global for the whole JVM
In Regular Expression Extractor I have stored reference name as prasad.
If I give my reference name to further scripts ${prasad} where ever I want it is working fine.
But I want to store these reference name as user defined variables (Global variables).
I am using only one thread group.
I am doing performance automation scripts so I want to store that reference name as user defined variable.
I didn't not understand properly,(Below Answer)..Can any one help me with brief explanation please...
This is stated in JMeter's best practices or mailing list answer:
Variables are local to a thread; a variable set in one thread cannot
be read in another. This is by design. For variables that can be
determined before a test starts, see Parameterising Tests (above). If
the value is not known until the test starts, there are various
options:
Store the variable as a property - properties are global to the JMeter
instance
To store in JMeter's "global variable"/property add JSR223 Sampler
props.put("a", vars.get("a"));
Now you can see you "global" variable ${a}
I have some test cases for a web application in Robot Framework. In some cases I define a unit and then validate this action by checking database and GUI. The variables which I use in define, should be available in validation in order to check details; keep in mind they are randomly generated in the test case. I have three approaches in mind to pass variables from define to validation:
Make variables global and use their global names further; it makes the scenarios ambiguous since the reader can't detect where did this variable come from without checking inner steps.
Pass variables to both define and validation keywords; scenarios look weird when vast number of parameters are required.
Save variables in a dictionary and pass it to both define and validation keywords.
Which one is the best? Are there any other ways to do the process? Are there any other pros and cons which I've forgotten?
3rd option is better to storing variables in dictionary.
There is similar way out also
Consider following is keyword
My Keyword
[Argument] #{data}
// get respective values from keys and use further for validation
${value1}= Get Template Value From List ${Key1} #{data}
${value2}= Get Template Value From List ${Key2} #{data}
Call above keyword as follows
*** Test Cases ***
Test data
My Keyword
... key1=value1
... key2=value2
So above code will increase readability as you know what kind of data your test case is using
As you are passing data at your test case level, you don't need to go anywhere else to find data.
I finally use a combination of #2 & #3. I used #3 in the top level of test cases and #2 for some inner keywords which don't need all the data and a subclass of that is sufficient for them.
I'd like to access attributes that are inside instances of defined types from other classes/instances.
This is very similar to a question asked on SO before - In Puppet, how can I access a variable/attribute inside a defined type?, however from what I understood the answer was specifically related to accessing parameters as opposed to arbitrary variables.
For example, given the following defined type:
define server (
$server_name = 'my_server'
){
$server_history = 'A long story'
}
I can successfully use getparam(...) to fetch server_name but I cannot do the same for server_history.
Also, if server was a class as opposed to to a defined type, accessing this variable is straightforward using something like server::serverhistory
Does anyone have any ideas on how to expose these variables? Or am I approaching this completely the wrong way?
Edit: For some higher level context on what I'm trying to do my server type gets instantiated by 3 other classes. A variable in the server type builds out some directory paths based on parameters provided to it by these classes (which naturally, are specific to those classes). There are some other classes that would like to use the directory path variable to place files there.
You ask
I'd like to access attributes that are inside instances of defined types from other classes/instances.
and you go on to clarify that you're after
arbitrary variables.
In fact, ordinary variables in the body of a defined type are not attributes of that type, nor of any instance thereof. They are not part of the accessible persistent state of instances of such types at all.
More generally, Puppet treats defined types just like native types in almost every observable way, but by the same token, it does not provide any features that serve to distinguish defined types as a special case. You are looking for such a feature, and it does not exist.
Since your design idea will not work, you'll need to think of an alternative. You say
my server type gets instantiated by 3 other classes. A variable in the server type builds out some directory paths based on parameters provided to it by these classes (which naturally, are specific to those classes). There are some other classes that would like to use the directory path variable to place files there.
Since the paths you're after are characteristic of specific classes, it makes sense for them to be accessible directly via those classes. It seems odd to me that you would even want to access them indirectly via resources declared by those classes.
I have multiple thread group for a test plan in jmeter. I want to define user defined value's to a particular thread group, the variable name can be repeated in another thread group for its user defined values.
When I tried doing the above it was picking up the last value of the same variable name across thread groups and not using it scope wise.
Using for jdbc requests with queries
I answere this "old" question for everyone who has the same Problem and is looking for a working solution. At least in JMeter 5.11 the answer of Dmitri T is not always true.
From the JMeter Documentation:
Note that the values defined by the Test Plan and the User Defined
Variables configuration element are made available to the whole test
plan at startup. If the same variable is defined by multiple UDV
elements, then the last one takes effect. Once a thread has started,
the initial set of variables is copied to each thread. Other elements
such as the User Parameters Pre-Processor or Regular Expression
Extractor Post-Processor may be used to redefine the same variables
(or create new ones). These redefinitions only apply to the current
thread.
A good and working solution for using local variables, that are only visible in the actual Thread Group, is to use the User Parameters Pre-Processor instead of the User Defined Variables configuration element.
Happy load testing ...
JMeter Variables have scope limited to current Thread Group only. To make JMeter variables visible for all Thread Groups you need to convert them to JMeter Properties. See How to Use Variables in Different Thread Groups guide for details on how to do it.
I got the solution. Example: If you have some test cases under a random order controller and like that you have multiple random controllers. The test case's contain a variable name for a jdbc request connection then you can add user defined variable inside the random order controller which will be used by only those test case's under it.
Like this you can scope the variable name to a particular random order controller