MuukTest offers the facility to use Global Variables in your test to make different actions and make easy test automation. In this article, you will learn how to use Global Variables.
Content:
Global Variables
A global variable is a variable that is declared in the global scope in other words, a variable that is visible from all other scopes. In this case, the variable will be available on all test scope.
To declare a Global Variable, you can use two options: from Account or from Test.
Declare a variable from Account
To declare a Global Variable from Account, you need to go to the Account page.
There, you will find different tabs to manage different options in your MuukTest account. To manage all global variables, you need to select the Global Variables tab.
In this tab, you will be found a table with all variables that you created before. To create a new variable, only need to click on Add global variable button and a modal will be shown on the screen.
In this modal, you need to put a name to your variable, to identify it.
Note: The name cannot contain spaces or underscore. It can not start with a number, but it could contain numbers before the first letter.
The value can be whatever alphanumeric string including symbols. When you fill the form, only click on the Save button and the variable will be saved in your account.
Now, you can see it in your variable list.
Declare a variable from Test
To declare a variable on the Test page, you need to follow the next steps.
First, you need to open a test. It can be the test that you want to use with variables or whatever test. In this case, the test can not be affected by the creation of the variable.
Select a step that accepts to Assign to Global Variable and click on it. To open this menu, you need to mouseover in the + button. A modal will be shown on your screen.
In the modal, you will see that the value wants to be assigned to a Global Variable. To follow the creation of a variable, you need to click on the New Global Variable button and a modal will be shown with the form to create a variable.
In this form, you need to put a name and a value to this variable to initialize it.
Note: The name cannot contain spaces or underscore. It can not start with a number, but it could contain numbers before the first letter.
After filling the form, you need to click on the Save button to save the variable.
The variable is saved successfully. And the way to check if it was saved correctly, you need to go to the Account page and select the tab Global Variables. You will see your new variable in your list.
Use a global variable in a test
Global variables have different uses that make easy test automation. The uses will be described next.
Use a variable in the step value
A variable can be used on a step value, and the new value of the step will be the value of the variable. To use a Global Variable in a Step Value, you going to open a test that you want to edit.
There, you select a Step that wants to modify the value.
To edit the Step Value, you going to click on the Edit button and a Text field will be shown on the screen.
MuukTest identifies when the user wants to use a Global Variable. To enable Global Variable mode, you need to write {{ and all variables will be shown. While you are typing, MuukTest starts to filter the variables.
When you select your variable, you have the possibility to save changes by clicking on the button.
Now, the value of your step is the value of a Global Variable.
Use a variable on the Base URL
Sometimes you need to have a dynamic URL to automate your test cases. For this reason, MuukTest has the possibility to modify your Base URL with a Global Variable.
To start to do this, you need to click on the Edit Test button that is located on Test Information.
Then, a modal will be shown on your screen. You will select the Starting URL to edit it.
Click on the Edit button and a Text field will be displayed.
On the Text field, delete what you need and start to write {{ to activate the Global Variable filter.
Write your Global Variable and select it.
When your variable is written, click on the Save button to save the changes.
With this, you can use Global Variables in your URL to have a dynamic URL.
Assign a value to Global Variable
Global Variables has the possibility to use globally on your test. To make this, you need to add some step value to a Global Variable.
First, you will choose a step and will mouse over with a + button. A menu with the following options will be displayed.
Clicking on the button Assign to Global Variable, a modal with the next form will be shown.
There, you will see the value that will be assigned to a variable. Also, a list with the variables to use.
Select a variable, and click it on Save to save changes. If you want to create another variable, click on New Global Variable to make a new one.
When finish, save the changes in your test by clicking on the Save changes button.
If everything is successful, the changes will be saved and you can use the variable with the value that you assigned.
Using a Global Variable in a JavaScript Snippet
MuukTest can use your variables in JS Snippets or return the JS Snippet result. In the next, you will find how to make that.
Use a Global Variable like a parameter
To use a Global Variable in a JS Snippet like a parameter, you need to have a JS Snippet that uses parameters, does not matter if is a verification JS Snippet or an execution JS Snippet.
First, you need to mouse over in + button to Add JS Snippet.
A modal with the next option will be shown. If you do not have any JS Snippet, you can add it by clicking on the New JS Snippet button.
Select from the list the JS Snippet that you want to use.
Then, you will see that the modal shows Advanced Settings. Click on it to open the option to add a parameter.
The JS Snippet has the option to add a Global Variable like a parameter.
For instance, you can select a variable that you want to use the value to interact with the JS Snippet.
When you finish selecting a variable, you can click on the Save button to save changes.
Now, in your test, you will see a JS Snippet with your variable.
Click on the Save changes button to save and start to use JS Snippets with Global Variables like parameters.
Use a Global Variable to get the value that a JS Snippet returned
To use a Global Variable to have the value that a JS Snippet returned, you need to have a JS Snippet that returns a value. In this case, you will use verification JS Snippet.
First, you need to mouse over in + button to Add JS Snippet.
Clicking on the button Assign to Global Variable, a modal with the next form will be shown.
Select from the list a JS Snippet that has the possibility to return a value.
When you select a JS Snippet, MuukTest detects the type and if it uses Global Variables. In this case, it is a verification JS Snippet, for instance, you need to write a value to validate.
If you click on Advanced Settings, you can assign the result of the JS Snippet to a Global Variable.
Select a variable from the list to have the value returned.
When you selected the variable, you can save the changes with the Save button.
In your test, you will see your verification JS Snippet with your variable assigned.
Only save the changes to start to use your JS Snippet with the return assigned to a Global Variable.
You have the possibility to make different combinations with these options to make better test cases and make excellent test automation.
Comments
0 comments
Please sign in to leave a comment.