[英]Cucumber 7 regex on step definition
我是 cucumber 和正則表達式的新手。 我目前正在為一個項目使用 cucumber core 7.2.0。
出於某種原因,我似乎無法讓正則表達式在步驟定義中起作用。
例如我有以下
Scenario: User tries to login
When I enter valid credentials for test@test.com
然后在步驟定義 class
@When("I enter (.*) credentials for {word}")
public void iEnterMyCredentialsAsUser(String email) {
System.out.println(email);
}
雖然該功能發現找到的步驟定義很好,但在執行時我得到以下信息
io.cucumber.junit.UndefinedStepException:步驟“我為 testa30 輸入有效憑據”未定義。 您可以使用以下代碼段來實施此步驟:
@When("I enter valid credentials for testa30")
public void i_enter_valid_credentials_for_testa30() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}
基本上我只想關心 email 作為參數而不關心“有效”
要讓 Cucumber 知道您正在使用正則表達式,請以^
開頭並以$
結尾。 在此處查看詳細信息。
此外,不要混淆正則表達式和 cucumber 表達式。 當您使用正則表達式方法時,不支持像{word}
這樣的語法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.