Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add tags to data-driven tests in Robot Framework?

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).

like image 793
Anders Martinson Avatar asked Mar 11 '14 01:03

Anders Martinson


People also ask

How do you use force tags in Robot Framework?

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.


3 Answers

Tags can be added like this:

*** test cases ***       parameter1   parameter2  ER
testa                    value1a      value2a     ERa
    [Tags]    tag1
testb                    value1b      value2b     ERb
    [Tags]    tag1
like image 117
Dmitriy Zverev Avatar answered Oct 23 '22 17:10

Dmitriy Zverev


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

like image 28
Bart Vanherck Avatar answered Oct 23 '22 18:10

Bart Vanherck


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

like image 24
Bryan Oakley Avatar answered Oct 23 '22 18:10

Bryan Oakley