Optimizing Test Scenarios in Robot Framework: Reducing Redundancy and Enhancing Efficiency

45 Views Asked by At

I need assistance with Robot Framework. How can I create test scenarios? By test scenarios, I mean combining multiple test cases together. For example, if I have the following test cases:

1.Login backend

2.Add content backend

3.Edit content backend

4.Check frontend content section

And then I have the following test scenarios: 1.Login backend -> Add content backend -> Check frontend content section will update 2.Login backend -> Edit content backend -> Check frontend content section will update

Alright, so now, how can I proceed to write these in Robot Framework? Currently, in the *** Test Cases *** section, I have written out 2 test cases:

  1. Login backend -> Add content backend -> Check frontend content section will update
  2. Login backend -> Edit content backend -> Check frontend content section will update

Both of these test cases have the Login backend and check frontend content section commands repeated. Is there a way for me to reduce code redundancy? For example, could I write Login Backend and check frontend content section as functions and then call them later in the *** Test Cases *** section?

1

There are 1 best solutions below

0
Sam Maksymyshyn On

Sure, you could wrap any actions as a keyword (the RobotFramework name for functions/methods) and then reuse it.

It is explained in the User Guide.

So, Login backend, Edit content backend, and Frontend content section should be updated could be keywords that could be reused. For example, very high-level:

  1. You could have a resource file backend.robot with keywords, like:
*** Keywords ***
Login backend
  [Arguments]  ...
  ...

Edit content backend
  [Arguments]  ...
  ...

Frontend content section should be updated
  [Arguments]  ...
  ...
  1. And example of a file with tests, e.g., sanity.robot:
*** Settings ***
Resource  libs/backend.robot

*** Test Cases ***
Backend content could be added
  Login backend    <arguments here if any>
  Add content backend   <arguments here if any>
  Frontend content section should be updated  <arguments here if any>

Backend content could be edited
  Login backend    <arguments here if any>
  Edit content backend   <arguments here if any>
  Frontend content section should be updated  <arguments here if any>