Following the concepts of BDD, our team tries to generate scenario’s on a high level without describing much of the behavior (see example below). While our project within Katalon grows, we find that duplication is occurring within the Step Definition file. In order to lower maintenance and to increase code readability, we want to create method’s for the ‘shared steps’. How to cope with this in Katalon and where to store the files? Create a separate class (in Include > Scripts?), create a Keyword, etc?
Example scenarios: Given I am on the profile-page <user> When I add <housing> to the profile Then I should get a warning Given I am on the profile-page <user> When I add <schooling> to the profile Then I should get a warning
A sample code for “When I add to the profile” would be:
- Click on <xxx> module
- Click on name
- Click on Save
- Enter address
In some situations, the duplication can be resolved with a scenario outline and we can have all the code under a single step by using if or switch statements without duplicate code. However, in many cases there are too many variations in the modules and having them under the same step makes it complex (for example, step 1 and 2 are the same but the rest deviates). In those situations, we still want to be able to de-duplicate as much code as possible and therefore thinking in terms of methods / keywords etc.
Coming back to the question: What would be wise? Create a separate class and create methods? Create the methods within the Step Definition files? Create a keyword? Etc.
Hope its clear!