簡體   English   中英

Cucumber BDD 自定義參數定義不適用於帶有示例的功能

[英]Cucumber BDD Custom Parameter Definition not working for feature with examples

我正在嘗試使用 Serenity Cucumber BDD 編寫步驟定義

這是我的特點:

@test1
      Scenario Outline: I need to try to Sign up as a new user 
            Given I have clicked on the Sign up link
            When I enter <username> and <password>
            And I click on sign up button
            Then I must see Success message
            Examples:
                  | username   | password |
                  | user001    | test123  |
                  | user002    | test123  |

我的步驟定義


 @When(value = "I enter {word} and {word}")
    public void iAddUserNameAndPassword(String userName, String password) {
        user.addNewUserInfo(userName, password);

如何在步驟定義中使用“userName”和“password”而不是“word”

我嘗試給出如下所示的參數定義,但它不起作用

@ParameterType("word")  // regexp
    public String userName(String userName){  // type, name (from method)
        return new String(userName);       // transformer function
    }

如果您使用的是 Cucumber,那么您幾乎是正確的。 我實際上不知道 Serenity 是做什么的。

參數類型注釋應該有一個正則表達式的值。 此正則表達式應與您的步驟中使用的值匹配。

@ParameterType("[a-z0-9]+")
public String userName(String value){
    return new value;
}

@ParameterType("[a-z0-9]+")
public String password(String value){
    return value;
}

然后在您的步驟定義中,您可以使用帶注釋的方法的方法名稱作為參數類型。

@When("I enter {userName} and {password}")
public void iAddUserNameAndPassword(String userName, String password) {
    user.addNewUserInfo(userName, password);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM