Groups and Reuse
"Reuse" is one of the more basic principles of programming. Instead of copy-pasting the same twenty lines of code over and over, you write them ONCE inside a method and call it whenever you need to. This principle works precisely the same in the world of automated testing - let's see how it is done!
Read more about reusing steps here.
- Let's start by making a new test similar to the previous one:
- Start by selecting the '+' and the '1' steps.
This is done in the same way as selecting multiple files in a file explorer - hold the Ctrl key while left clicking on the steps or left click, OR mark an area around the steps you want to copy:
- Click on the group button on the top right:
- The steps will combine into a single group step.
- You can name your group with a name. We named it "+1"
Let's now add another step after the new group:
- Click on the "+" button > Groups Tab > there you will find a group with the name "+1". Click it to add the group as a new step.
- After doing it twice you get this:
- Note that for the test to be successful now you will need to change the validation to -6.
- Double click on one of group steps
- This is the group from the inside:
- You can now make changes to this group.
- Let's record more steps (make sure the Recording button is red, and add more interactions in the recorded app in the browser:
- Note that since we already used this group three times in our test we now changed all three of them. Furthermore, any additional groups of this type we add will be created with this change!
- Click on Properties and change the name of the group to "+4" to reflect its new functionality.
- To get back to the test either click the Back button or on the name of the test on the top left.
Note: In some cases, you do not want your group to be reusable because the group is relevant to this test only. You can go to the properties and uncheck the 'Allow reuse' checkbox.
Copy a group
You can also reuse the group using the copy button.
This copy will create a pointer to the group as before, so each change in the group changes the data in all instances of the group.
Note: If you need to duplicate the group, copy the steps within the group and create a new group.
Delete a group
If you need your group to be deleted, please do the following:
- Delete the group from all the tests you used it.
Remove reuse option:
- Navigate to 'Automate' (Test List).
- Navigate to tab 'Shared Steps'.
- Search for your group.
- Delete it.
Note: Delete from the Action List, do not delete it from the tests, just remove the option to reuse it and add it to tests again.