Enroll in Selenium Training

Every invention or discovery, be it in the software industry or any other industry, runs the same course of events. First, a team or an individual discovers it. For example, the discovery of APIs. Then, it is implemented in a single use case to witness the effects and outputs. In our case that would be inducting APIs into graphic programs to free the programmer to deal with the graphic device in the late 1960s. Then, it starts to pick up in other applications and use cases as well. That would equate to websites, remote procedures, web calls, etc. Finally, it becomes so involved in the system that it is used repetitively, with variations and a separate branch of testing emerges to keep it in check.

This stage gives rise to repetitive testing behavior by putting in different data for the same tests. It ensures the system will not break in any circumstance. To resolve this repetitive behavior, testers introduced data-based testing (or data-driven testing) where not only test case scripts but the process of data input can be automated, which ultimately speeds up the system.

A similar thing can be achieved in testRigor with the help of global variables and data sets in the "Test Data" option. This post will highlight the same concept with real practical examples.

What are global variables in testRigor?

To perform test cases with different values, we need global variables. They are located inside the "Test Data" option available in the side tool panel. test data option in testRigor

Since it is inside the "Test Data", it is obvious that global variables in testRigor will relate to the data we will use inside our test cases. This assumption is actually correct. When we are building test case scripts, as a standard scripting rule, hardcoded values are never recommended for use. In the earlier posts on fixing failed test cases in testRigor and performing validations on test scripts, we made use of hardcoded values to keep things simple. From now on, to achieve the same goals, we will be using "Global Variables" instead.

When we enter the "Test Data" part, we see two options: global_variables

  • Global variables.
  • Data sets.

Global variables are variables that can be directly used in a test case script without hardcoding the value. For instance, let's say I have ten test cases and all of them have one instruction line:

enter "704 Hauser St, apt 114" into "Address"

In this, "704 Hauser St, apt 114" is the value that goes inside the input variable "Address". After some time, a requirement comes where the address changes to "322 Maple St.". Now the problem is that since we hardcoded the value earlier, we have to open each test case and manually change this value to the new value. Considering there are many fields on which we execute a test case and such requirements are frequent, manual work can be time-consuming as well as error-prone.

To save us from this hectic work, testRigor provides global variables where we can define a variable and a value associated with it. In our example, we can provide the following:

Global variable name: my_address

Global variable value: 704 Hauser St, apt 114

In our test cases, we can use the variable name instead of the hardcoded value and testRigor picks up the variable value from the global variable section. Now when the requirement comes to change the value of the address, all we need to do is jump to the Global Variables section, find the address variable and change the value once. The changes reflects in each of the test cases on the next run. This way we can save a lot of time on our test case execution with global variables.

How to add a global variable in testRigor?

Adding global variables is very easy in testRigor. Enter the "Global Variables" section in "Test Data" as shown above.

Click on Add. add global variable in testRigor

This will pop up a screen where we can add a global variable. It will show three options: How to select the type of global variable in testRigor

  • Type: The type of variable you are about to add. It can be text, hidden, file, or multiline.
    • Text: The global variable will be a text value like a name.
    • Hidden: The global variable will be a hidden value like a password.
    • File: The global variable will be a file.
    • Multiline: The global variable expands to multiple lines.
  • Name: The name of the variable you wish to keep. This name will be used as an alias for the value associated with it in the test cases.
  • Value: The value associated with this variable.

Fill out these values and click Add to add the variable. How to add a new global variable in testRigor

The variable will then be visible in the below section which lists all the variables. Global variables in testRigor Once added, we can now use this global variable in our test cases.

How to use global variables in testRigor test case?

To use global variables, first, we will create a test case normally and then incorporate global variables into it.

For this demonstration, we will be using the register page of the demoqa.com website. Head on to testRigor, create an account if you haven't already, and move on to create your test case.

Write the following instruction sets for the test case:

open url "https://demoqa.com/register"
enter "Harish" in "First Name"
enter "Rajora" in "Last Name"
enter "harishrajora" in "UserName"
enter "harish123" in "Password"
click checkbox left of "I'm not a robot"

The test case should pass and the following screen should be visible: Passed test case in testRigor.png

There are a lot of elements in the image above. If you wish to know about each of them, we have created a separate post just for this purpose.

In the above instruction set, we have used hardcoded values. As mentioned above, this is not a good development or testing practice in the software industry. Let's switch to global variables section and create the following variables: Listing global variables in testRigor.png

On page two, I have also saved the "I'm not a robot" value into "captchaText" variable. Now we need to replace the hardcoded values with the variable names. The instruction set will then look as follows:

open url stored value "URL"
enter stored value "firstName" in "First Name"
enter stored value "lastName" in "Last Name"
enter stored value "username" in "UserName"
enter stored value "password" in "Password"
click checkbox left of stored value "captchaText"

Press "Save and Retest" and the test cases will run as smoothly as they did with hardcoded values. Also, notice that unlike writing enter "<value> into <field>, we use the "stored value" keyword instead when dealing with global variables in testRigor. So the syntax becomes:

enter stored value <variable name> in <label>

This instruction, however, is just to give an example. The keywords of instruction will change according to the situation.

Up until this point, we have put the same amount of effort into both hardcoded as well as with global variables. Actually, we may say that we have put extra effort into global variables in saving these variables and their respective values. However, the real importance of global variables where they help us accelerate things faster is when more test cases join in. Let's say I now have a test case for the Login page as follows:

open url stored value "loginURL"

enter stored value "username" into "UserName"

enter stored value "password" into "Password"

Here, I had to just enter one new variable as loginURL and the rest two remains the same. Now, if there is a third test case where any of the values from these variables is required, the tester can directly put the variable name. In the future, any changes required in the username, for instance, just need a change in the variable "username" value and hundreds of test cases will reflect the change.

Data sets in testRigor

The second option we see alongside "Global Variables" is "Data sets". These are clubbed together because their aim is similar i.e. reducing the test setup and maintenance time, cutting the costs, and eliminating repetitive manual work from the system.

As global variables are one variable that can be at hundreds of places, data sets are values that are hundreds and used at a single place. In scenarios where a tester may need to input hundreds of values in a single field, a data set can do that job automatically. Let's see how to do it.

How to use data sets in testRigor?

To demonstrate the working of data sets, we will use the same demoqa login page as above. The task is to enter three usernames and three passwords on this page with a single test case. For this, we will visit the "Test Data" section and click the "Data Sets" link.

In this screen, click on "Add" to add a new data set. Data set in testRigor

Next, write the name and description of the data set. How to create data set name in testRigor

Clicking on "Add" will take you to the data set screen. how to add a variable in testRigor

Here, there are two options: Variables and Rows.

Variables here have the same meaning as they had in the global variables sections. It will replace the hardcode values from the test case scripts. On our login page, we have two variables - username and password (as described in the previous section).

The next option is to add "Rows". This is where we create multiple data for the same variable. Select "Rows" and Click "Add", then"Add Row". Select rows in testRigor data set

Add the data corresponding to a new row. How to add a new row in data set in testRigor

One row corresponds to one set of data passed during a single execution. You can add as many rows as you want and they pass sequentially to the test case. Here for demonstration, we will add three rows. Data set filled rows in testRigor

The process will remain identical. The added rows are shown on the same screen. For explanation, one row is expanded to show details in the above image. All these rows links to our data set and ready to use.

Let's hop on to the test case screen to link this data set to our test case that will execute on the Login Page.

Click Link Data Set located on the right side of the test case panel. Link data set button in testRigor

This will list down all the available data sets to link to this test case. Since we have only one data set, that will be listed here. how to link data set to test case in testRigor.png

Click on Link and then "Close" to close this panel.

Now you can click on "Re-test" to run the test again with the linked data set. retesting in testRigor

When the tests executes, a dropdown will appear that will show the results for each row we added to the data set. row wise results for data set run in testrigor

You can check the result of other rows as well which should pass as the overall test case result is "Passed".

With this demonstration, we have successfully implemented global variables and data sets in our test case to speed up the overall process with lower maintenance work. We can conclude our learnings on this topic here.

What's next?

Global variables and data sets eliminate repetitive value entry into multiple test cases. This post was in continuation with the series that focuses on testRigor and the features and elements it offers to its customers. Moving ahead on the same path, we will learn the concept of reusable rules and how to create them on the platform in our next set of posts. You can subscribe to the newsletter to get the intimation of its publication and hundreds of other tutorials on varying topics.

Fix A Failed Test Case
Fix A Failed Test Case
Previous Article
Reusable Rules in testRigor
Reusable Rules in testRigor
Next Article
Harish Rajora
I am a computer science engineer. I love to keep growing as the technological world grows. I feel there is no powerful tool than a computer to change the world in any way. Apart from my field of study, I like reading books a lot and developing new stuff.

Similar Articles

Feedback