3

According to Creating user keywords:

User keywords can be created in test case files, resource files, and test suite initialization files.

So I'm wondering what's the best practice regarding this.

I'm organizing my tests in one file per website page I'm testing. I also have Resource file for library importing and global variables, and one __init__ file per tests file to include test setup and teardown.

Where in this structure would higher level keywords fit?

2 Answers 2

5

I don't think there is a universally agreed-upon set of best practices.

In my experience, the very best practice is to create at least one library file per website page (see page object library for one such implementation). I rarely use .robot files for keywords, almost everything my team does is to create keywords in python. I've worked at four different companies that used robot, and the one that took this approach has been the most successful.

You write "one __init__ file per tests file", which I don't understand. You can put an __init__ file in a directory, but I don't know how you can associate an __init__ file with a test file. I do not like using __init__ files inside of folders; in my experience they make it slightly harder to run individual suites.

As for organizing tests, one file per page is a good starting point. In my experience, comprehensive suites may need to be split into more than one file per page. For example, one app that I work with uses one suite just for the left navigation on the page, another that is specifically for the header and footer, and another for the main area. The main area can have multiple sections (we call "panels"), each of which has a set of tests in its own file.

1

In my experience, the best practice to write a user keyword depends upon the scope of that keyword. Robot framework is flexible enough that it can search keywords in all resource files and even in nested resource files.

If I am using a keyword which is required only for a given suite, then it is better to write that keyword in keywords section of that suite.

If I have a keyword which is used in multiple test suites then it is better to define it in some keywords file which is acquired in those test suites. (It makes your project neater.)

If I have a keyword upon which multiple keywords depend then it is best to write it in a global resource file.

I follow this structure(helps me in maintaining a clean structure): enter image description here

As you can see in this structure that i am using a directory for global resources which is used by API suites and GUI suites both. But also i have another "resources" folder in both API and GUI suites which contain those keywords which are required by API and GUI test suites respectively. This helps me in maintaining API keywords and GUI keywords separately.

Also in some of my projects, I have used multiple resource files to make my project more clear and easy to maintain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.