Turn your manual testers into automation experts! Request a DemoStart testRigor Free

How to use reusable rules or subroutines in testRigor?

We often have a few common steps that we need to execute in most test cases. Writing those test steps again in many test cases causes repetition. Also, if there is any change in one of those steps, we must update that step in every test case. In programming, ‘subroutines’ solve this problem. These small collections of steps are identified by a unique name and called in a program whenever needed.

Similarly, testRigor has introduced ‘Subroutines’ in test automation using an easy way known as ‘Reusable Rules’. We can define all those repetitive test steps as a reusable rule with a name. Call those test steps by writing that name when required in test cases. So, let’s see how we can do that.

Let’s start with the prerequisites.

Step 1: Log in to your testRigor app with your credentials.

Step 2: Set up the test suite for the website testing by providing the information below:

  • Test Suite Name: Provide a relevant and self-explanatory name.
  • Type of testing: Select from the following options: Desktop Web Testing, Mobile Web Testing, Native and Hybrid Mobile, based on your test requirements.
  • URL to run test on: Provide the application URL you want to test.
  • Testing credentials for your web/mobile app to test functionality which requires user to login: You can provide the app’s user login credentials here and need not write them separately in the test steps then. The login functionality will be taken care of automatically using the keyword login. Filling out this field is optional and not mandatory.
  • OS and Browser: Choose the OS Browser combination on which you want to run the test cases.
  • Number of test cases to generate using AI: You can simplify your test creation further by opting to generate test cases based on the App Description text. This feature works on generative AI.

Step 3: Click on Create Test Suite.

On the next screen, you can let AI generate the test case based on the app description you provided while creating the Test Suite. However, for now, select do not generate any test, since we will write the test steps ourselves.

Step 4: To create a new custom test case, click Add Custom Test Case.

Step 5: Provide the test case Description and add the test steps.

Test Case: Add Reusable Rules

Consider we have a test case to search for an item on the Amazon website, add it to the cart, and check if it is added. The testRigor test steps in plain English are as follows:
enter "SAMSUNG Galaxy S24 Ultra Cell Phone" into "search"
type enter
click "SAMSUNG Galaxy S24 Ultra Cell Phone"
click "256GB"
click "Titanium Yellow"
click "Add to cart"
click "No Thanks" if page contains "Phone Accident Protection Plan"
check that page contains "Added to cart"

In many test cases, we frequently use these test steps to add this product to the cart. So, we can create the above steps as a reusable rule and avoid duplication. Let’s see how we can do that.

Step 1: Click on the “Reusable Rules” link on the left side menu.

Step 2: On the left-hand side of the screen, you can see filters to search the existing ‘Reusable Rules’:

  • Filter by name: You can search and filter by name if there are many rules.
  • Filter by label: You may choose to search and filter by label instead of name.

Since we do not have any reusable rules defined by the search criteria, no results were found.

To create a new reusable rule, provide the following:

  • Name: Provide a meaningful name according to the scenario. We are providing the name “Add to Cart Amazon”.
  • Label: If there are different purposes for the same rule, like if it can be used for checkout or adding a product to a cart, then provide different labels separated by a comma.
  • AI-based rule: If you need to generate the steps by AI, you can select this checkbox.
  • Steps: Mention the above testRigor test steps for ‘Reusable Rule’ here.
  • Once it’s done, click Save.

Step 3: The rule will be displayed on the reusables rules page.

Step 4: Once done, go to the test case page and use the reusable rule by writing its name in any test case. So, let’s create a use case where the user first validates if they have signed in, then adds a product to the cart, goes to the cart, and then checkout. So the testRigor test script in plain English is:
check that page contains "Hello, sign in"
add to Cart Amazon
click "Go to Cart"
click "Proceed to Checkout"

Step 5: You can see that the execution result also includes all the steps mentioned in the reusable rule.

Test Case: Use Dynamic Test Data Values in Reusable Rules

In our previous example, we provided the product name in the rule, so we cannot use that rule for every test scenario. Considering we need to search for different mobile phones, we can’t use the rule created above here.

We can provide a variable name (e.g., product) in the rule and change its values using the test data to overcome that. To do that, we first need to save the ‘product’ as a variable to hold test data.

You can refer to this link to set text as test data. Now, let’s create a new rule.

Step 1: testRigor’s reusable rule steps with stored value (test data) will be:
enter stored value "product" into "search"
type enter
click stored value "product"
click "256GB"
click "Titanium Yellow"
click "Add to cart"
click "No Thanks" if page contains "Phone Accident Protection Plan"
check that page contains "Added to cart"
We can save this new rule with dynamic test data values as “Dynamic add to cart Amazon”.
Step 2: Add a new test case and write the test step as:
check that page contains "Hello, sign in"
dynamic add to cart Amazon
click "Go to Cart"
click "Proceed to Checkout"

Test Case: Convert Existing Test Steps to Reusable Rule

In the above scenario, we first created a new reusable rule and then used it in a new test case. However, if you have existing test cases and notice that the few test steps are repeating in most of them, then you can convert those test steps into reusable rules later using testRigor.

For example, we have an existing test case with the following steps:
check that page contains "Hello, sign in"
enter "Galaxy Z Fold 5 Cell Phone" into "search"
type enter
click "Galaxy Z Fold 5 Cell Phone"
click "256GB"
click "Icy Blue"
click "Add to cart"
click "No Thanks" if page contains "Phone Accident Protection Plan"
check that page contains "Added to cart"
click "Go to Cart"
click "Proceed to Checkout"

Now, we need to convert these test steps into a reusable rule. Follow the below steps:

Step 1: Click the ‘Reusable Rule’ from the left side menu.

Step 2: Fill in the details, like the rule name and label, and add the test steps for which we need to create a rule. Here, we are not creating the rule for all the steps; instead, we are creating the rule for the below steps:
enter "Galaxy Z Fold 5 Cell Phone" into "search"
type enter
click "Galaxy Z Fold 5 Cell Phone"
click "256GB"
click "Icy Blue"
click "Add to cart"
click "No Thanks" if page contains "Phone Accident Protection Plan"
check that page contains "Added to cart"

Add these to the rule steps, click Save, then Find and Replace Steps.

Step 3: Once you click Save, then Find and Replace Steps, a pop-up will appear with a list of all the test cases that already use these steps. Please note that only the test cases that use all of these test steps will be displayed.

Now, you can select which test cases need to be replaced with the rule name by selecting the checkbox and clicking Replace Selected.

Step 4: You will get a confirmation pop-up as “ X Test Cases Refactored.”

Step 5: Now, let’s go back and check the test case; the steps are replaced with the rule name.

Test Case: Edit Rule Name

Consider if you need to change the rule name, maybe to make the rule name more meaningful or for some other reason. So, changing it manually for every test case is complex.

Here, testRigor provides an easy option for that. Let’s see how we can do that.

To explain this scenario, let’s take the example of the previous rule itself – “existing rule add to cart”.

Step 1: Click the Reusable Rules from the left side menu.

Step 2: Now click the rule name “existing rule add to cart”.

Step 3: Change the name to “existing rule Samsung phone add to cart”.

Step 4: Change the label also if required.

Step 5: Now click “Save, then Find and Update Name”.

Step 6: Once you have saved it, a pop-up will be displayed with all the existing test case IDs with the old rule name, asking us to confirm which test cases need to be updated with the new rule name.

You can select which test cases need to be replaced by selecting the checkbox and clicking the “Update Selected” button.

Step 7: You will get a confirmation pop-up as “ X Test Cases Refactored.”

Step 8: Now, let’s go back and check the test case; the rule name is updated.

Execution Results

Once the test is executed, you can view the execution details, such as execution status, time spent in execution, screenshots, error messages, logs, video recordings of the test execution, etc. In case of any failure, logs and error text are available easily in a few clicks.

You can also download the complete execution with steps and screenshots in PDF or Word format through the ‘View Execution‘ option.

testRigor’s Capabilities

Apart from the simplistic test case design and execution, some advanced features help you test your application using simple English commands.

  • Reusable Rules (Subroutines): You can easily create functions for the test steps you use repeatedly. You can use the Reusable Rules to create such functions and call them in test cases by simply writing their names. See the example of Reusable Rules.
  • Global Variables and Data Sets: You can import data from external files or create your own global variables and data sets in testRigor to use them in data-driven testing.
  • 2FA, QR Code, and Captcha Resolution: testRigor efficiently manages the 2FA, QR Code, and Captcha resolution through simple English commands.
  • Email, Phone Call, and SMS Testing: Use simple English commands to test the email, phone calls, and SMS. These commands help validate 2FA scenarios, with OTPs and authentication codes sent to email, phone calls, or text.
  • File Upload/ Download Testing: Execute the test steps involving file download or file upload without the requirement of any third-party software. You can also validate the contents of the files using testRigor’s simple English commands.
  • Database Testing: Execute database queries and validate the results fetched.

testRigor enables you to test web, mobile (hybrid, native), API, and desktop apps with minimum effort and maintenance.

Additional Resources

You're 15 Minutes Away From Automated Test Maintenance and Fewer Bugs in Production
Simply fill out your information and create your first test suite in seconds, with AI to help you do it easily and quickly.
Achieve More Than 90% Test Automation
Step by Step Walkthroughs and Help
14 Day Free Trial, Cancel Anytime
“We spent so much time on maintenance when using Selenium, and we spend nearly zero time with maintenance using testRigor.”
Keith Powe VP Of Engineering - IDT
Related Articles

All-Inclusive Guide to Test Case Creation in testRigor

Test cases fuel test automation tools. Over the years, the process of automating these test cases has undergone many changes. ...

How to Create Tests Using Live Mode in testRigor?

testRigor offers a unique capability known as the ‘Live Mode‘ to create and validate test cases. Using it, you can ...

CI/CD Series: testRigor and Azure DevOps

TestRigor manages different types of CI/CD tools in order to enhance with AI your workflows and pipelines. This time, we’ll ...
On our website, we utilize cookies to ensure that your browsing experience is tailored to your preferences and needs. By clicking "Accept," you agree to the use of all cookies. Learn more.
Cookie settings
Privacy Overview
This site utilizes cookies to enhance your browsing experience. Among these, essential cookies are stored on your browser as they are necessary for ...
Read more
Strictly Necessary CookiesAlways Enabled
Essential cookies are crucial for the proper functioning and security of the website.
Non-NecessaryEnabled
Cookies that are not essential for the website's functionality but are employed to gather additional data. You can choose to opt out by using this toggle switch. These cookies gather data for analytics and performance tracking purposes.