Siya
Siya

Reputation: 307

Testcase level validations in Robot framework?

I would like to know is there any way to control the validations for testcase level. we have tags, which are testcase selection level. I have a testcase which covers addition and subtraction of two numbers.

Here my requirement, both actions are in the same testcase but, if I mention 'add' testcase will execute only addition part and similarly sub. if we didn't specify any specification then it has to run both the operations. IS there any way to control these kind of scenarios in Robot? kind of if/else scenario in testcase level. We will mention our input while running the script. Of course we can write it in different testcases like, one for Sub and another one for Add but, in my case i have total of 100+ testcases are with this kind of scenario.

Sample code:

| Setting | Value | | * Test Cases * |

-----------------------------

| Testing1
| | [Tags] | PRIORITY:P0 | CATEGORY:NA | STC_DB_INDEX:NA

if {add}

| | Log | Addition of two numbers |
| | Run Keyword | addition | 20 | 25 |

if {sub}

| | Log | Subtraction of two numbers |
| | Run Keyword | sub | 10 | 5 |

Upvotes: 0

Views: 506

Answers (2)

Claudio Batista
Claudio Batista

Reputation: 341

Not sure if I understand what you need, but if you have a lot of repetition in your test you should consider a template approach like:

*** Test Cases ***
Add Variables Scenario   [Template]   Sum My Vars
   ${var1}   ${var2}   ${expectedResult1}   # one line is one test
   ${var3}   ${var4}   ${expectedResult2}

Substract Variables Scenario   [Template]   Substract My Vars
   ${var1}   ${var2}   ${expectedResult1}


*** Keywords ***
Sum My Vars
   [Arguments]   ${value1}   ${value2}   ${result}
   # do your validations ...

Substract My Vars
   [Arguments]   ${value1}   ${value2}   ${result}
   # do other validations ...

Basically with this you can call one or other keyword and each sum / substraction will always generate a distinct test case without much code repetition. If this is not what you are really looking for trying giving a bit more details and what you are really looking for

Upvotes: 0

Bryan Oakley
Bryan Oakley

Reputation: 385830

The simplest solution is to split your test in two. Many QA experts think each test should test exactly one thing, and I've found that to be a successful strategy.

So, put your add validation in one test, your subtraction in another. Then when you specify the "add" tag, only the "add" tests will run.

Upvotes: 1

Related Questions