Tags in Robot Framework

Contents
Введение
Применения тегов для включения/исключения тестов
Test Tags
Зарезервированные теги: skip и т.д.
Похожие статьи

Introduction

Tags are needed to be able to run only a certain part of the tests.

The simplest example: critical tests are run every day, less important ones have their own tag and are run once a week.

Along with [Documentation], [Setup], [Teardown], [Template] и [Timeout] [Tags] are test case settings (Settings in the Test Case section)

Official documentation settings-in-the-test-case-section , tagging-test-cases

Using tags to include and exclude tests

Let's look at the test in the file tags_demo.robot

It consists of three test cases, one with the tag critical, the second with the tag weekly and the third without tags.

Note that there are four spaces between Tags and the tag name.

There should be at least two, but four is harder to confuse with a single space.

Если запустить этот тест без опций никакого эффекта от тегов не будет.

*** Settings *** *** Test Cases *** Critical Test [ Tags ] critical Do Something Important Weekly Test [ Tags ] weekly Do Weekly Checkup Regular Test Log To Console Test Without Tags *** Keywords *** Do Something Important Log To Console Doing Something Important Do Weekly Checkup Log To Console Doing Weekly Checkup

robot tags_demo.robot

==================================================================== Tags Demo ==================================================================== Critical Test Doing Something Important Critical Test | PASS | -------------------------------------------------------------------- Weekly Test Doing Weekly Checkup Weekly Test | PASS | -------------------------------------------------------------------- Regular Test Test Without Tags Regular Test | PASS | -------------------------------------------------------------------- Tags Demo | PASS | 3 tests, 3 passed, 0 failed ==================================================================== Output: C:\Users\Andrei\robot\output.xml Log: C:\Users\Andrei\robot\log.html Report: C:\Users\Andrei\robot\report.html

From the logs it is clear that all three test cases have been launched.

To run only tests with the critical tag

robot --include critical tags_demo.robot

==================================================================== Tags Demo ==================================================================== Critical Test Doing Something Important Critical Test | PASS | -------------------------------------------------------------------- Tags Demo | PASS | 1 test, 1 passed, 0 failed ==================================================================== Output: C:\Users\Andrei\robot\output.xml Log: C:\Users\Andrei\robot\log.html Report: C:\Users\Andrei\robot\report.html

To run all tests except critical

robot --exclude critical tags_demo.robot

==================================================================== Tags Demo ==================================================================== Weekly Test Doing Weekly Checkup Weekly Test | PASS | -------------------------------------------------------------------- Regular Test Test Without Tags Regular Test | PASS | -------------------------------------------------------------------- Tags Demo | PASS | 2 tests, 2 passed, 0 failed ==================================================================== Output: C:\Users\Andrei\robot\output.xml Log: C:\Users\Andrei\robot\log.html Report: C:\Users\Andrei\robot\report.html

Test Tags

What was previously called Force Tags. Applies to all test cases, no matter if they have [Tags] settings or not.

Let's add the Test Tags section to Settings from the previous example, which will contain the all and default tags, and we won't make any other changes.

*** Settings *** Test Tags all default …

robot tags_demo.robot

and

robot --include all .\demo\Tests\tags_demo.robot

and

robot --include default .\demo\Tests\tags_demo.robot

They will give the same result as in the previous example . All three tests will pass.

If you try to exclude one of these tags, there will be an error.

robot --exclude all tags_demo.robot

[ ERROR ] Suite 'Tags Demo' contains no tests not matching tag 'all'. Try --help for usage information.

robot --exclude default tags_demo.robot

[ ERROR ] Suite 'Tags Demo' contains no tests not matching tag 'default'. Try --help for usage information.

Excluding a common tag

To exclude a common tag from a test case, you need to specify it in the [Tags] settings with a minus sign.

Let's remove the default tag from the Weekly Test test case

*** Settings *** Test Tags all default *** Test Cases *** Critical Test [ Tags ] critical Do Something Important Weekly Test [ Documentation ] Test has no 'default' tag. [ Tags ] weekly -default Do Weekly Checkup Regular Test Log To Console Test Without Tags *** Keywords *** Do Something Important Log To Console Doing Something Important Do Weekly Checkup Log To Console Doing Weekly Checkup

robot --include default tags_demo.robot

In this test suite the result will be similar

robot --exclude weekly tags_demo.robot

==================================================================== Tags Demo ==================================================================== Critical Test Doing Something Important Critical Test | PASS | -------------------------------------------------------------------- Regular Test Test Without Tags Regular Test | PASS | -------------------------------------------------------------------- Tags Demo | PASS | 2 tests, 2 passed, 0 failed ==================================================================== Output: C:\Users\Andrei\robot\output.xml Log: C:\Users\Andrei\robot\log.html Report: C:\Users\Andrei\robot\report.html

Two tests were performed.

Now that there is a test case that does not use the default tag, you can exclude it and not get an error.

robot --exclude default tags_demo.robot

==================================================================== Tags Demo ==================================================================== Weekly Test :: Test has no 'default' tag. Doing Weekly Checkup Weekly Test :: Test has no 'default' tag. | PASS | -------------------------------------------------------------------- Tags Demo | PASS | 1 test, 1 passed, 0 failed ==================================================================== Output: C:\Users\Andrei\robot\output.xml Log: C:\Users\Andrei\robot\log.html Report: C:\Users\Andrei\robot\report.html

It is still not possible to exclude the all tag.

robot --exclude all tags_demo.robot

[ ERROR ] Suite 'Tags Demo' contains no tests not matching tag 'all'. Try --help for usage information.

Reserved tags

Users are generally free to use any tags that work in their context.

However, there are certain tags that have a predefined meaning for the Robot Framework itself, and using them for other purposes may have unexpected results.

All special tags that the Robot Framework has and will have in the future are prefixed with robot:.

To avoid problems, users should not use tags with these prefixes unless they actually enable special functionality.

The current reserved tags are listed below, but more such tags will likely be added in the future.

robot:skip

Let's mark the Critical Test test case from the previous example with the robot:skip tag

*** Settings *** Test Tags all default *** Test Cases *** Critical Test [ Tags ] critical robot:skip Do Something Important Weekly Test [ Documentation ] Test has no 'default' tag. [ Tags ] weekly -default Do Weekly Checkup Regular Test Log To Console Test Without Tags *** Keywords *** Do Something Important Log To Console Doing Something Important Do Weekly Checkup Log To Console Doing Weekly Checkup

Now during a normal launch the test case will be skipped

robot tags_demo.robot

======================================================================== Tags Demo ======================================================================== Critical Test | SKIP | Test skipped using 'robot:skip' tag. ------------------------------------------------------------------------ Weekly Test :: Test has no 'default' tag. Doing Weekly Checkup Weekly Test :: Test has no 'default' tag. | PASS | ------------------------------------------------------------------------ Regular Test Test Without Tags Regular Test | PASS | ------------------------------------------------------------------------ Tags Demo | PASS | 3 tests, 2 passed, 0 failed, 1 skipped ======================================================================== Output: C:\Users\Andrei\robot\output.xml Log: C:\Users\Andrei\robot\log.html Report: C:\Users\Andrei\robot\report.html

If you explicitly specify that you need to include the robot:skip tag, the test will be selected and immediately skipped.

robot --include robot:skip tags_demo.robot

============================================================================== Tags Demo ============================================================================== Critical Test | SKIP | Test skipped using 'robot:skip' tag. ------------------------------------------------------------------------------ Tags Demo | SKIP | 1 test, 0 passed, 0 failed, 1 skipped ============================================================================== Output: C:\Users\Andrei\robot\output.xml Log: C:\Users\Andrei\robot\log.html Report: C:\Users\Andrei\robot\report.html

Article author: Andrei Olegovich

Related articles
Robot Framework
Basics
RFBrowser
Set Variable
if else: conditionals
in: check if smth belongs to list
Loops
Change Variable Value
New Line
[Tags]
Collections: lists, dicts
JSON
Pass Argument to a Keyword
Evaluate
Robot in PyCharm

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: