標籤

出於文件的目的,你可能希望按類別過濾測試計劃或方案。開發人員可能希望基於相同的類別執行測試。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     |