Question

I am trying to add tags to data-driven tests in Robot Framework. I have created keywords for the templatized tests and tables for the data similar to the following:

# Test case file
*** settings ***
Resource       libraries.txt
Test Template  My Test Template

*** test cases ***       parameter1   parameter2  ER
testa                    value1a      value2a     ERa
testb                    value1b      value2b     ERb

# Template file
*** Keywords ***
My Test Template
  [Arguments]  ${parameter1}  ${parameter2}  ${ER}
  ${result}=  Do Something  ${parameter1}  ${parameter2}
  Should Be Equal As Strings  ${result}  ${ER}

How can I add (possibly distinct) tags for testa and testb?


It turned out to be PEBKAC. I was not indenting the tag statement. Those double spaces did me in (again).

Was it helpful?

Solution 2

There are several ways to add a tag.

Only test specific is like:

*** Test cases ***
Test A
  [tags] tagA tagB
  Log  This is test A

It is possible to add a tag to all testcases in your file by placing a Force Tags in your settings:

*** Settings ***
Force Tags  NewTag

For more information you can check the user guide: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#tagging-test-cases

OTHER TIPS

Tags can be added like this:

*** test cases ***       parameter1   parameter2  ER
testa                    value1a      value2a     ERa
    [Tags]    tag1
testb                    value1b      value2b     ERb
    [Tags]    tag1

One solution is to modify your keyword to take tags as arguments. Then you could do something like this:

*** Settings ***
| Test Template | My Test Template

*** test cases ***       
| testa | value1a  | value2a | ERa | tag1 | tag2
| testb | value1b  | value2b | ERb | tag2 | tag3

*** Keywords ***
| My Test Template
| | [Arguments] | ${value1} | ${value2} | ${er} | @{tags}
| | log | value1: ${value1}
| | log | value2: ${value2}
| | log | er: ${er}
| | Set tags | @{tags}

When run, testa will have the tags tag1 and tag2, and testb will have the tags tag2 and tag3

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top