标签
出于文档的目的,你可能希望按类别过滤测试计划或方案。开发人员可能希望基于相同的类别运行测试。Gherkin 允许你通过 Tags 的用户对功能以及各个场景进行分类。在下面的示例中,请注意上面的 Feature 关键字是标记“@Automation”。Gherkin 将此标识为“@”符号的用户标记。在这个例子中,工程师希望明确这些测试用于自动化,而不是每个测试都是自动化的,一些测试必须通过手动 QA 完成。
另请注意,标签 @Production 已添加到方案测试用户锁定中。在此示例中,这是因为此方案仅在应用程序的生产环境中处于活动状态。开发人员不希望他们的沙盒帐户在开发过程中被锁定。此标记允许他们强制执行此测试仅针对生产环境运行。
最后,Scenario Outline 的标签为 @Staging。出于此示例的目的,这是因为正在使用的帐户是暂存帐户,并且不能在其他环境中工作。与 @Production 标记一样,这可确保这些测试仅在 Staging 环境中运行。
这些只是你可以使用标签的位置,方式和原因的几个示例。最终,这些标签对你和开发人员都有意义,可以是任何东西,并且可以根据你的需要进行分类。
@Automation
Feature: Product Login
As a user, I would like to be able to use my credentials to successfully
login.
Rules:
- The user must have a valid username
- The user must have a valid password
- The user must have an active subscription
- User is locked out after 3 invalid attempts
- User will get a generic error message following
login attempt with invalid credentials
Background: The user starts out on the login page
Given the user is on the login page
Scenario: The user successfully logs in with valid credentials
This scenario tests that a user is able to successfully login
provided they enter a valid username, valid password, and
currently have an active subscription on their account.
When the user signs in with "valid" credentials
Then the user should be logged in
Scenario: The user attempts to log in with invalid credentials
This scenario tests that a user is not able to log in when
they enter invalid credentials
When the user signs in with "invalid" credentials
Then the user should be logged in
@Production
Scenario: The user is locked out after too many failed attempts
This scenario validates that the user is locked out
of their account after failing three consecutive
attempts to log in
When the fails to log in 3 times
Then the user should be locked out of their account
@Staging
Scenario Outline: The user successfully logs in with their account
This scenario outlines tests in which various users attempt
to sign in successfully
When the user enters their <username>
And the user enters their <password>
Then the user should be successfully logged on
Examples:
| username | password |
| frank | 1234 |
| jack | 4321 |