Steals
Steals

Reputation: 137

How do I keep Robot test suites DRY?

I'm halfway through a set of automated tests using the Robot Framework, and am starting to notice a lot of repetition. At the moment, my tests are organized by the page being tested (i.e. homepage, login page).

The uncertainty I'm feeling is that some tests are word-for-word repeated in two different test suites, with only the setup differing; but on the other hand, with the refactoring I've done, it feels like the keywords themselves are the test cases. I just want to know if there's a more standard practice way of doing this.

I've listed a trivial example below:

common.robot

...
*** Keywords ***
User logs in
   # login logic here
...

home_page.robot

...
*** Test Cases ***
Verify user login
   User logs in
...

other_page.robot

...
*** Test Cases ***
Verify user login
   User logs in
...

Upvotes: 2

Views: 552

Answers (1)

AkshayDandekar
AkshayDandekar

Reputation: 435

If you want to share test keywords, you can do that on many levels.

  1. So you could define a resource.txt file and put all your common keywords in there and then call them for different tests.
  2. You can have a single parent test where you are simply reusing keywords with the differing parameters.
  3. You could also feed the parameters through a list and call the same keyword in a For loop.

That being said, regarding your bigger concern of how to organize the structure of your test suite, that is a much-discussed topic and no single answer would suffice. You could look at the Pekka's writings on this topic (Link). Test-framework-design is an 'art-form' similar to code design.

Upvotes: 2

Related Questions