引數化步驟

在編寫 Gherkin 時,有時你可能需要為實施測試計劃的工程師引數化可重用性的步驟。步驟通過正規表示式捕獲組接收引數。 ( 工程注意: 如果正規表示式中的每個捕獲組都沒有匹配的引數,則可能會出現“CucumberException:Arity mismatch”丟擲)在下面的示例中,我們決定用雙引號括起引數,以及 as 接受整數作為引數。

 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 

    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. 

        Given the user is on the login page
        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

        Given the user is on the login page
        When the user signs in with "invalid" credentials
        Then the user should be logged in

    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

        Given the user is on the login page
        When the user fails to log in 3 times
        Then the user should be locked out of their account