Reusable Rules | Bondar Academy
Course: Mastering testRigor
Module: Reusability and Optimization
Instructor: Artem Bondar
Lesson Summary
In this lesson, we explore reusable rules in Test Trigger, which help eliminate duplication in test scripts. Here are the key points discussed: Understanding Reusable Rules Reusable rules allow you to create a single command that can replace repetitive steps across multiple test cases. This is particularly useful when: The structure of your application changes (e.g., renaming or relocating pages). You want to enhance the readability of your test cases. Creating a Reusable Rule To create a reusable rule: Navigate to the Reusable Rules section. Click on New Rule and name your rule (e.g., Navigate to Form Layouts page ). Add relevant labels for easier searching. Input the steps (e.g., click Forms , click Form Layouts ) and save the rule. Using Reusable Rules in Test Cases Once created, you can use the reusable rule in your test cases: Type the command (e.g., navigate to ) and select the rule from the suggestions. This simplifies the test case and enhances readability. Updating Test Cases If changes are made to the reusable rule, you can use the Save and Find and Replace feature to update all related test cases simultaneously. Benefits of Reusable Rules Overall, reusable rules: Optimize code and improve reusability. Simplify maintenance by allowing changes in one place. Enhance the clarity of test cases. To quickly navigate to a reusable rule from a test case, use Command + click on Mac or Control + click on Windows. In summary, reusable rules are a powerful feature in Test Trigger that streamline the testing process and improve overall efficiency.
Video Transcript
In this lesson, we will talk about reusable rules in Test Trigger. So reusable rules are very useful to remove the duplications from your test scripts. So let's get into it. So this is our current test suite and so far we already have 17 test cases. And if we look into the test cases implementation, for example, let's start from the beginning. For example, if to open the very first test, it starts with forms and form layouts, right? We navigate to Form Layouts page. The next test starts with the same exact thing. Click Forms and click Form Layouts. The next step is the same. Another test case, Forms and Forms Layouts. So to write several test cases, in our example, we had to copy paste the steps to navigate to first Forms and then to the Form Layouts. But imagine the situation if, for example, the designer decided to change the name for the Form Layouts page, and it was renamed to the Form Components page. In this case, you need to go to all of your test cases and rename Form Layouts into the Form Components. Or even worse scenario, if Form Layouts was moved, for example, under Extra Components in the menu, then you need to change the entire flow. How would you navigate to the Form Layouts page in the first place? And this is a lot of work and a lot of maintenance. Much better way to handle this is to create a single reusable rule. For example, if we replace these two steps, click on Form and click on the Form Layouts, with just a single command. For example, navigate to the Form Layouts. And calling this command, we will just navigate to the Form Layouts page. And you can do this in the test trigger by using reusable rules. So let me show you how to do this. Here on the left, we go to Reusable Rules section, and I click over here. Currently, we don't have any rules, so let's create the first one. If I click the new rule, this will just open this window to the right. By default, it's already open. And we need to give a name to our rule first. And let's say we create the first rule to navigate to the Form Layouts page. And I call it like that. Navigate to Form Layouts page. Then you need to provide labels to your rules. You need to provide at least one label. So label is useful when you search your rules later on to quicker find the needed rule, additionally to the name. And I suggest to use at least one label that is related to the page, which this rule belong to. For example, we call it Form Layouts page. So this rule navigate to Form Layouts page by context is related to the Form Layouts page. So we add this tag. And now we just need to put those steps inside of the Steps section. So I could type, click Forms, and then click Form Layouts page. Layouts. And that's it. And I click just a Save button. So I click Save, and new rule was created here. Now I'm going back to the test cases right here, opening the test case where I wanted this rule to use. The very first one, quick edit. And now instead of calling click Forms and Form Layouts, I can type navigate to. And look, when I start typing nav, TestRigger immediately start looking into the already created rules. And it's showing me this pop-up. Hey, I find the rules which start with nav. And this rule is navigate to Form Layouts page. And all you have to do is just select this rule, and that's it. So this rule is added. And now you can simply delete these two lines. And that works. This also makes test case even more readable than it was before. Instead of click here, click there, we say, hey, navigate to Form Layouts page. It's pretty clear. So I can now update and retest, and this test should work as it worked before. All right, and test passed successfully as expected. Now we can use this new created rule inside of the other test where we use navigation to the Form Layouts page. For example, in this test, we have click Form Layouts. In this test, click Form and click Form Layouts. But instead of going to each individual test and changing this, there is a faster way. So if I go into Reusable Rules one more time, open this, I have a button Save and Find and Replace over here. So if I click on this, TestRigger immediately will find all the test cases where the steps related to this reusable rule are used in the other test case. So I can select either which one do I want to update or not, or I can choose Replace Selected, so it will be replaced in all six test cases. So I click Replace Selected, and going back to the test cases, open, for example, test case number two. Here and View Steps, and now you can see the step was updated navigate to Form Layouts page. And all tests that were updated, now you can see the label outdated. It means that the step of the test case was changed, but this test case was not executed yet with the updated steps. It's fine for us because we know that it should work as expected. Now let's make a refactoring for our current test suite and create a new reusable rules for all navigation across the application for other test cases. For example, here we are navigating to the model and overlays page, right? So I just copy this step, go into Reusable Rules, creating a new rule. Navigate to Toaster page, Toaster page, and here Steps, Model and Overlays, Toaster page. And I click Save, and then Find and Replace. It will automatically replace the test cases where this page was used. Okay, this one is done. What else? Let me open just the second tab, so we will review them one by one. So this is Models. This is Models, this is a Toaster page. Toaster page, Form Layouts page, here is everything refactored. I'll list some dropdowns, let's see. So we have Toaster page, and nothing to change over here. Going back to the first page, Tooltips. Review Steps, okay, we need to navigate to the Tooltip page. New rule. And Save, Find and Replace. All right, I believe that's it. If we miss something, we're gonna add it a little bit later. And now, going back to the test cases, and let me show you some of the magic that will begin to happen when you have more and more rules added into the Reusable Rules section. How can you use those rules? So I'm gonna show you how you can use those rules. So if I create a new test, and for example, this test will be about navigate to different pages, for example. And when I want to navigate to different pages, I don't need to use like click here, click there, and so on, I just call the page where I want to navigate, for example. Navigate to, and here we go, look, I have the list of the pages that I want to navigate, and I just select the step that I wanna use. For example, I want to navigate to the Toaster page, and then I want to navigate to, let's say, Date Picker page, right? And then I just add and run, and this test will use a reusable rules to navigate across the pages. Yeah, you can see, so first navigate it to the Toaster page, then we click some forms, and navigate it to the Date Picker page. So now using the reusable rules, you improve readability and remove the duplications from the test. So if I look at the steps, now you can read navigate to Toaster page, navigate to Date Picker page, looks very nice. And if the location, for example, of the Date Picker page inside of the application will be renamed or changed or something like this, all you have to do is to update just implementation of the rule itself. You go to the, for example, Date Picker page rule and change these steps. But you will not need to go and change the actual step inside of your test case. This will simplify the maintenance by a lot. And one more thing, if I click Quick Edit, and let's say I want to find out, okay, what is this step and what is the implementation? You can use Command click on Mac or Control click on Windows. So hold this key, click on this, and from the test case, you will be navigated automatically to the implementation of this rule. So very convenient when you need quickly to navigate to the rule and find out, okay, what are the steps of this reusable rule? All right, so let's quickly summarize what we did in this lesson. Reusable rules is a great way to optimize your code and improve reusability. So you go to Reusable Rules, create the rule with a meaningful name for your test, update the rule, and you can either save or save and replace. So with save and replace, the trigger automatically will replace the steps of your test case with a new reusable rule. And then you can use those rules inside of the test cases. And if from the test case level you want to open this reusable rule, you can use Command click on Mac or Control click on Windows to open this rule and review the implementation. All right, that's it, guys, and see you in the next lesson.