Global Variables | Bondar Academy
Course: Mastering testRigor
Module: Reusability and Optimization
Instructor: Artem Bondar
Lesson Summary
This lesson focuses on global variables in testing, which allow for the reuse of variable values across different test cases. Key Concepts Global Variables: Variables defined globally that can be accessed in multiple test cases. Test Data Section: Where global variables are created and managed. Creating Global Variables To create a global variable: Navigate to the Test Data section. Click the Add button to create a new variable. Define the variable name and value. For example: superuseremail with value [email protected] superuserpassword with a hidden value for security. Using Global Variables in Tests Once created, global variables can be referenced in your tests: Replace hard-coded values with global variables using the syntax stored value . Example usage in a test case: stored value: superuseremail stored value: superuserpassword Conclusion Using global variables simplifies test management by avoiding repetitive hard-coded values. They can be found under the Test Data section, and accessed in tests using the stored value syntax. In summary, global variables are essential for maintaining consistency and efficiency in testing.
Video Transcript
In this lesson, we will talk about global variables. So global variables are the variables that can be used across different test cases. You can define them globally and then use the values across different test cases. So let's get into it. For this example, we will use one of the tests that we used before, InputFields. So if I open this test, quick edit. Previously, I used the hard-coded value of the email address and password just inside of the test. But let's imagine the situation that we would like to use a test user across of all of our test cases, or some particular type of the user for particular types of the test cases. And we don't want to copy-paste the user email that we want to use inside of the test case every time for every test case. Instead, we can define this account globally as global variable, and then use a reference, this global variable inside of the test. So let's do this. To create the global variable, you need to scroll down on the left, click Test Data, and here's the section of global variables. Currently, we don't have anything here, so click on Add button, and then create the first variable. The first value will be the type of text, and we provide the variable name. Let's say we want to create a super user email. And the value will be superuserattest.com, something like this. So for example, this is our test account that we want to use inside of the test, and click Add. And also, we will need a password for this user, right? So instead of using text, you can use a hidden. So hidden will hide the value that will be stored inside of this variable, so it will be more secure. So I now will call it superuserpassword, and provide the value, for example, like this. And I type this, but you don't see the actual value, right? Because this is hidden, and I click Add as well. That's it, so both variables are created. Now they can be used inside of the test. So let me open a new tab, just for the convenience. And here I need to find the test where we want to use it. So this is input fields, click Edit. And now instead of hard-coded value, I just use the global variable. Stored value, and provide the global variable value, superuseremail over here. And in the password, instead of typing hello that we typed in before, I type stored value, and the value for the password, superuserpassword. And we'll do it right here. And the same thing we can do inside of the assertion. So here I will type contains this, and equals to this. And for this assertion, it should also pass, so let's double check our credentials. Okay, let's make it lowercase. Instead of superuser, we'll take it superuser at test.com. In this case, it will match the regex expression right here. And this assertion will pass as well, because we are validating here test.com and any value right here. And that's pretty much it. So let's run this test. All right, test passed successfully. Let's check out the screenshot. And here we go. We typed superuser at test.com inside of the input field. So global variable was used successfully. So that's pretty much it. Let's quickly summarize what we did in this lesson. So if you have a certain values that have to be shared across different test cases, the best way would be to use a global variables. Global variables can be found under the test data. And then inside of the test, you just call this global variable with a standard prompt syntax stored value and the global variable name. All right, that's it, guys, and see you in the next lesson.