What are Global Variables?
Global variable are the variables possessing constant value throughout the project. These variables are beneficial when they are to be shared among various Test Case(s)/Function library/Gherkin/Sparkin/Service Repository/Suite.
Modifications (if any) in the value of Global variable are done only at a single place; instead of modifying it at every place where this variable has been used in the project.
These variables can be either user-defined i.e. the users can make their own variables as per the requirements and use them throughout the project or System defined i.e the Global Variables are created by the System but the user can provide its value.
Getting familiar with the Global variable buttons:
To create a Global variable for the project, follow the steps mentioned below:
- Go to Tools in the menu bar.
- Select Global Variable. A Global variable window will get open as shown below:
- Your can view view where the particular Global Variable has been used. To do so, select a Global Variable and click on the UsedBy button. UsedBy pane will show the name, full path, description and component type of the UsedBy artifact of the selected Global Variable.
- Default Browser & Default Mobile Device are the two system defined Global variables which will exist in each & every project (even in a new project.)
- Click Add.
- A new row will get added to the User defined Global Variable list.
- Name field marked with * is mandatory.
- String is the default Data type for a Global variable, but user can choose suitable data type for it by clicking on Data Type cell.
Global Variable Encryption
With the latest OpKey release, OpKey has come up with an advanced feature of Global Variable Encryption which allows the users to create global variables with encrypted values by using Secured String Data Type.
Once the Global variables are created in the encrypted format, there original value are not displayed to the users until and unless they are being decrypted by giving decryption password set in OpKey Admin at project level.
To create Global variables with encrypted values, Select Secured String from Data Type Dropdown and enter the value.
The value will be entered in encrypted format as shown below:
This Encrypted value cannot be edited. Although if you wish to edit or view value in decrypted format then, Click the Decrypt value icon. It will decrypt the value [provided there is no encryption password set at the project level].
If there is any encryption password set at the project level, then a pop up window will open up as follows. You need to enter the encryption Password and click OK.
The Value will get displayed in the decrypted format.
When these global variables are used in our Test scripts then their values are displayed in encrypted format throughout the project.
Once the Execution is completed, you have an option of decrypting the values by clicking on the Decrypt Result icon, where you need to enter the encryption password [if any].
You can also Export the result in Encrypted or decrypted format for the Detailed report.
Multiple values for Global Variables
You can also assign multiple values to a Global Variable i.e a single global variable can have multiple values.
To do so, select List from Data Type Dropdown.
Enter multiple values to the Global Variable. Select any default value from this list. This value can be changed at runtime.
Changing Values of Global Variables at Runtime:
- You can change the value of the Global variables at runtime.
- To do so, opt for the Advanced Settings in the Execution Wizard window.
- Click next till you reach the Global Variable settings window.
- Select any global variable whose value has to be changed.
- If the Global Variable is of List Type then, Select any default value from the list [for the runtime execution].
- If the Global Variable is of Secured String Type then, click Decrypt value icon
- If the Global Variable is of Secured String Type then, click Decrypt value icon.
A pop up window will get open. Enter the encryption password set at the project level.
Click Ok. Now, you will be allowed to edit the value at runtime.
Click Finish to proceed with the Execution.
Adding Collection & KeyValuePair type of Global Variables:
There is are two new variable type added in OpKey: Collection & KeyValuePair. Collection Variable allows you to add multiple values of String, Integer, Double, DateTime & KeyValuePair type and use them accordingly. You can add your own private collection variable and use them across your tests. There are some collection & KeyValuePair variable specific keywords added in this OpKey release.
Click on Add, enter name, select Collection of Global Variable Type from the list. From here, you can add multiple values of String, Integer, Double, DateTime & KeyValuePair type.
Let us first add String of type of Collection Global Variable.
Click on Add Collection button to add multiple Strings, as required.
Here, we have added few Strings of Collection type of Global Variables.
Similarly, you can add other types (Integer, Double, DateTime & KeyValuePair) of Collection type of Global Variables, as required.
Let us add now KeyValuePair type of Global Variable.
Click on Add, enter name, select KeyValuePair as a type of Global Variable from the list, as shown below.
Note: There are some Collection & KeyValuePair type specific keywords in OpKey. For details, you can refer: Collection Keywords.