About
You assign tags to features and scenarios to organize and run them by some criteria. For example, you can use tags to specify the operating system or environment in which the test should run, the browser that the test should check, the application subsystem or functionality that should be tested, and so on. You can then iterate through the list of features and scenarios, check their tags and run the features and scenarios that match your conditions.
Set a tag
You set tags in the Gherkin editor. Enter them before the feature or scenario description. Tags use a simple @tag
syntax:
As you can see in the image above, you can assign multiple tags, if needed. Simply separate them with spaces and make sure to put @
before each tag.
Notes:
-
You can apply tags to the following Gherkin elements:
Feature
Scenario
Scenario Outline
(orScenario Template)
Examples
Test steps cannot be tagged.
-
A tag you set for a
Feature
applies to allScenarios
of thisFeature
.A tag set for a
Scenario Outline
(orScenario Template
) applies to theExamples
element in thisScenario Outline
(Scenario Template
). -
Tag names are case-sensitive. For example,
@reports
and@Reports
are different tags. -
Tag names can include spaces (TestComplete treats everything between two
@
characters as a tag name).
Run by tag
Option 1 – Run from the UI
-
In the Project Explorer, right-click the Scenarios node and select Run Tagged by tag-name from the context menu (if the Project Explorer panel is hidden, select View > Project Explorer from the main menu to display it):
This command will run all the features and scenarios that have the specified tag set for them.
Option 2 – Run as a test item
You can make a “tag run” a test item and run features and scenarios by a tag along with other project tests as part of your project run:
-
Open the Test Items page of your project editor. To do this, double-click the project and select Edit > Test Items from the context menu, or double-click the project node in the Project Explorer and then switch to the Test Items tab:
-
On the tab, create a new project item.
-
Click the ellipsis button in the Test column and select the desired test in the subsequent dialog:
TestComplete will add the “tag run” to the test item list. It will run BDD tests when you run the entire project or if you run the test item to which the “tag run” is linked:
Option 3 - Run from the command line
To run feature files and scenarios by tag, you can use a command line like this one:
TestComplete.exe project-suite-file /project:project-name /test:"Scenarios|@tag1" /run
For more information on other arguments, see TestComplete Command Line.
Option 4 - Run by tag expression
Some frameworks, like Cucumber, can run a combination of tags like @tag1 and @tag2
, or @tag1 and not @tag3
. To do this in TestComplete, you write script code that will iterate through the features and scenarios and run them from script.
The script function below is an example of such code. It iterates through the features and scenarios in your project and runs those features and scenarios that have the @Win10
tag assigned and don’t have the @LoginForm
tag assigned. The main function to run is RunByTag()
. The function that checks the tags is checkBDDItem()
. If you copy this code to your tests, re-write the checkBDDItem()
function to check the condition you need.
When checking tags, make sure to specify @
before the tag name.
JavaScript, JScript
// Run features and scenarios (@Win10 and not @LoginForm)
function RunByTag(){
// Iterate through features
for(i = 0; i < Features.Count; i++) {
var feature = Features.Item(i);
// Call a custom function to check feature tags
if (checkBDDItem(feature))
feature.Run();
else
// Iterate through feature scenarios
for(j = 0; j < feature.Scenarios.Count; j++) {
scenario = feature.Scenarios.Item(j)
// Call a custom function to check scenario tags
if (checkBDDItem(scenario))
scenario.Run();
}
}
}
// Check feature and scenario tags
function checkBDDItem(BDDItem) {
return BDDItem.Tags.Contains("@Win10") && !BDDItem.Tags.Contains("@LoginForm");
}
Python
# Run features and scenarios (@Win10 and not @LoginForm)
def RunByTag():
# Iterate through features
for i in range(0, Features.Count):
feature = Features.Item[i]
# Call a custom function to check feature tags
if checkBDDItem(feature):
feature.Run()
else:
# Iterate through feature scenarios
for j in range(0, feature.Scenarios.Count):
scenario = feature.Scenarios.Item[j]
# Call a custom function to check scenario tags
if checkBDDItem(scenario):
scenario.Run()
# Check feature and scenario tags
def checkBDDItem(BDDItem):
return BDDItem.Tags.Contains("@Win10") and not BDDItem.Tags.Contains("@LoginForm")
VBScript
' Check feature and scenario tags
Function CheckBDDItem(BDDItem)
CheckBDDItem = BDDItem.Tags.Contains("@Win10") And Not BDDItem.Tags.Contains("@LoginForm")
End Function
' Run features and scenarios (@Win10 and not @LoginForm)
Sub RunByTag
' Iterate through features
For i = 0 to Features.Count - 1
Set Feature = Features.Item(i)
' Call a custom function to check feature tags
If CheckBDDItem(Feature) Then
Feature.Run
Else
' Iterate through feature scenarios
For j = 0 to Feature.Scenarios.Count - 1
Set Scenario = Feature.Scenarios.Item(j)
' Call a custom function to check scenario tags
If CheckBDDItem(Scenario) Then
Scenario.Run
End If
Next
End If
Next
End Sub
DelphiScript
DelphiScript does not support BDD functionality.
C++Script, C#Script
// Run features and scenarios (@Win10 and not @LoginForm)
function RunByTag(){
// Iterate through features
for(i = 0; i < Features["Count"]; i++) {
var feature = Features["Item"](i);
// Call a custom function to check feature tags
if (checkBDDItem(feature))
feature["Run"]();
else
// Iterate through feature scenarios
for(j = 0; j < feature["Scenarios"]["Count"]; j++) {
scenario = feature["Scenarios"]["Item"](j)
// Call a custom function to check scenario tags
if (checkBDDItem(scenario))
scenario["Run"]();
}
}
}
// Check feature and scenario tags
function checkBDDItem(BDDItem) {
return BDDItem["Tags"]["Contains"]("@Win10") && !BDDItem["Tags"]["Contains"]("@LoginForm");
}
For information on accessing features and scenarios in scripts, see Scripting.