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).
The robot framework allows tags to give the test cases free metadata. The tags can be set in a file using “Force Tags” and “Default Tags”. It is possible to give tags for a single test case using [Tags] just like [Template]. Let us take an example to understand how we use tags.
Tags can be added like this:
*** test cases *** parameter1 parameter2 ER
testa value1a value2a ERa
[Tags] tag1
testb value1b value2b ERb
[Tags] tag1
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With