You can annotate your test scripts with tags to organize and run them by some criteria. For example, you can assign tags to all tests working with certain feature or running in certain environments, and then easily run all the tests for that feature or environment.
Set a tag
-
In the keyword test editor, if the Tags text box on the toolbar is not visible, click to show it.
-
In the Tags edit box, type the needed tag in the following format:
@tag-name
If you need multiple tags, separate them with spaces and start each tag with the
@
character. -
Save the changes.
Notes:
-
A tag name should start with the
@
character. Don’t put spaces between@
and the tag name, or anywhere in the tag name. Spaces are used as tag separators. -
Don’t use parentheses in tag names. They have a special meaning.
-
Tag names are case-sensitive. That is,
@reports
and@Reports
are different tags.
Run by tag
Option 1 – From the UI
-
In the Project Explorer panel, right-click the project node and then select a tag from the Run submenu (if the Project Explorer panel is hidden, select View > Project Explorer from the main menu to display it):
TestComplete will run all the tests – scripts, keyword tests, BDD scenarios and BDD features – that match the selected tag.
Option 2 – Run as a test item
-
Open the Test Items page of your project. To do this, right-click the project node in the Project Explorer and then select Edit > Test Items from the context menu, or double-click the project in the Project Explorer and then switch to the Test Items tab.
-
On the Test Items page, add a new test item to your project.
-
In the Execution entry column, click the ellipsis button and select the needed tag in the subsequent Select Test dialog:
TestComplete will add the “tag run” to the test item list. It will run all the tests that match the selected tag when you run the entire project or if you run the test item to which the “tag run” is linked:
When you run this test item or when you run the entire project, the test engine will execute all the tests that match the specified tag.
Option 3 – From the command line
To run tests that match a tag, use the /test
argument or the /tags
argument to specify the needed tag:
TestComplete.exe project-suite-file /project:project-name /test:"@tag1" /run
– or –
TestComplete.exe project-suite-file /project:project-name /tags:"@tag1" /run
To learn about TestComplete command line arguments, see TestComplete Command Line.
Run by tag expression
Option 1 – Run as a test item
-
Open the Test Items page of your project editor. To do this, double-click your project in the Project Explorer and then go to the Test Items tab, or right-click the project node and select Edit > Test Items from the context menu.
-
On the Test Items page, click New Test Item or New Child Test Item to add a new test item to your project.
-
Click the ellipsis button in the Execution entry column. In the subsequent dialog, select [Tag Expressions]:
-
Click the ellipsis button in the Parameters column. Specify the desired tag expression in the Value column of the subsequent dialog:
You can either enter the expression, or specify a project or project suite variable that stores the expression:
Notes on tag expression syntax
-
Use
@
before tag names, that is, use@tag1
rather thantag1
. -
To combine tags, use the
and
,or
andnot
operations, for example:@tag1 or @tag2
@tag1 and not @tag3
not @tag5These operations don’t depend on the scripting language you use in your TestComplete project. That is, for example, in JavaScript projects you should use
and
,or
andnot
rather than&&
,||
and!
—@tag1 and not @tag2 ← Correct!
@tag1 && !@tag1 ← Incorrect! -
If needed, you can use braces to group tags, for example:
@tag1 and (@tag2 or @tag3)
(@tag1 or not @tag2) and (not @tag3 or @tag4)
Option 2 – Run from the command line
To run script tests and BDD features and scenarios that match a tag expression, use the /tags
command-line argument:
TestComplete.exe project-suite-file /project:project-name /tags:"@tag1 or (@tag2 and @tag3)" /run
To learn about TestComplete command-line arguments, see TestComplete Command Line.
Test order
Whenever you run tests by tags or tag expressions, the test order is not set, that is, the test engine runs the tests in an arbitrary order. If the order matters, you need to run tests in another way. For example, you can create test items, one for each test. Test items run in the explicit order – from top to bottom. See the description of the Test Items page.
Test Results
After running all the tests that match the specified tag or tag expression, TestComplete will collect their results in a single log and show the results grouped by the test names: