Tags in Robot Framework
| Введение | |
| Применения тегов для включения/исключения тестов | |
| 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:continue-on-failure и robot:recursive-continue-on-failure
Used to enable the mode continue-on-failure.
-
robot:stop-on-failure и robot:recursive-stop-on-failure
Used to disable the mode continue-on-failure.
-
robot:exit-on-failure
Stop all execution if a test with this tag fails.
-
robot:skip-on-failure
Mark a test for skipping if it fails.
-
robot:skip
Mark a test for unconditional exclusion.
-
robot:exclude
Mark test for absolute skipping.
-
robot:private
Mark keyword as closed.
-
robot:no-dry-run
Mark a keyword that will not be executed in idle mode.
-
robot:exit
Added to tests automatically when execution is stopped correctly.
-
robot:flatten
Enable the alignment keyword at runtime.
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