Script05variables
·SCRIPTING 05: WHAT ABOUT VARIABLES?
We are going to talk today about the variables and parameters that you will use in your code. After we are done with the correlations from the last post, we will replace the remaining differences with variables . These are different from the correlations in the sense that they are not generated by the server. They are defined in advance by us, the testers.
To work with them we will first create them. Afterwards we will replace them all over our code, on all the remaining differences found on our two recordings. Last we will define them to make them work differently, depending on what is the nature of the value that we will type.
Lets start with the first step.
CREATE THE VARIABLES
Whenever you identify that there is a difference in the code that is not a correlation, most probably it is a variable. You will be able to see it and recognize the plain value that you typed while recording.
For each one of those differences, you must create a variable.
I recommend you that at a beginning you just create an empty variable. Just name it in a way that easily identifies it. Use names such as UserID, ProductNumber, Password, FlightID, etc. Just have it there ready to be used.
Don’t worry for now about the type of each variable, parameter or however your scripting tool calls it. Just make sure it is a default variable and that it contains the initial value. The value that you used to record it.
Create them at the beginning of the code of your script, or on the variable creation module. Do this in the way that your scripting tool manages them.
REPLACING VARIABLES
You have the variables ready. Now we will find where is the value and replace it with the variable.
This may be the easiest step. You will just comb down your code until you are sure all the remaining differences are changed by the variables.
This is just like assigning actors to the characters on a theater play. You have the role of Romeo on the play as the main role. You must look for the actor and assign mister Rad Peet to the main role. Then you will go to Juliet. You will assign the role to Meagan Fatz. Follow this until you have all the characters assigned to an actor. After that you will deal with roles, rather than actors.
You must do this even with the silly roles; trees, clouds and birds need an actor. Make sure you cover them too.
INDICATE THE TYPE OF VARIABLE AND DATA, THEIR ROLE
Once you have replaced all the data with the variables, you will proceed to define them. We will give them a type if you wish.
Think of this as the archetypes that they will follow on the play. Some examples of archetypes in any story are such as the villain, the wizard, the hero, the damsel in distress, the sidekick, and so on.
Here we will focus on some other types. These are the core of the performance testing practice.
- The immortal deity
- Use It & Loose It (UILI)
- The Jealous/Loyal
- Just one for you
- The unique
THE IMMORTAL DEITY
This role is the best for a variable. It is like a god. You will be able to use the same value as many times as you want and it will not wear off. This same value can be used ad infinitum, again and again. If you want to put in your script a value in particular, you can use it as many times as you wish. Nothing will happen with it. It will not die no matter how much you use it!
It is like a God, a deity, so it will be omnipresent, meaning that it can be be everywhere at the same time. It can be used by everyone at the same time if needed. Which is why it makes it so wonderful for a load test. Every virtual user will be able to use that value at the same time. It will be everywhere.
USE IT ‘N LOOSE IT
This next one is not so great. Is anything but the opposite to immortal. This one keeps the characteristic that everyone can use it. It is still everywhere, but disappears once someone uses it.
So in essence this is available to everybody to pick it. But once someone uses it, it is no good to use anymore, by anyone. This type requires you to be careful, as getting new ones may be difficult.
This is just like a pile of apples in the grocery store. Anyone can pick one, or two, or more. But once you eat that apple, that particular one, it is gone forever into your gut. No one else can ever eat it again and you must work to get more apples.
THE JEALOUS/LOYAL
This one has the characteristic of the immortal. The value will never die and you will be able to use it again and again, as many times as you need. But has the disadvantage of being jealous. It can be with only one person at a time, and when it is with that person, no one else can be with it.
Think of this one as a car. All your family can drive that car as many times as they wish. But only one at a time will be able to drive it. If your brother wants to use the car, he has to wait until you are done with it.
This one is great as it will never die. You just have to be careful of how you manage it to ensure no one tries to use the same value at the same time.
JUST ONE FOR YOU
This type is available to everybody to use it. Actually everyone has access to each value. But once someone uses it, it is gone… at least for that person. As everybody else may be able to use it. But only once. After that, that is it for that person.
Something like getting chickenpox when you are a kid. Everyone can get it. It is available for everybody! But once you get it, it is done. You wont be able to get it again. No mater how many chickenpoxy people you hug. Once for you and done.
THE UNIQUE SPECIAL
This is the worst data type of them all. It has none of the good qualities of the others. The behavior of it is very possessive as well because once taken, no one else can use it.
It is not immortal at all. Once you use it, it is dead. Gone for ever and ever, disappeared, making it the worst of them all. Because we as load testers want to execute the process several times. But if we killed it once we use it, we will need as many new values for each time we plan to run the process.
Maybe we may need more, you know, for those time we fail and must start again.
THE HAND HOLDERS
The last is not a classification of the variable itself, but a behavior you can assign to them.
Some data values will be only good if used together with a matching pair of value. A clear example for this is a user and a password. None of them will work if you don’t type the one that matches with another.
To use them, you must link these special types. You must get their little hands to be held to each other. Make sure they go together always. A variable will follow the behavior of the lead. One of them must wear the pants in the house!
CONCLUSION
After you replace the variables in your script’s code, you must define what type are they. By knowing the type, you will be able to configure them accordingly to ensure that they will behave as expected. After you do that, the script will be almost awesome!
Then it will come the time to test the script that you have created to do a test. What?!
Haha yes, your QA process needs to go through QA as well to ensure it has quality. But we will check that next time. This was a long ish post, so for now, Vamonos!
Besos <3
-Señor Performo