[英]Is there any way to send data from Java step definition class to feature file in Cucumber framework?
[英]Cucumber .feature file not picking up Step Definition in Java class
我正在為我的Java項目編寫一些黃瓜測試。 我的測試工作正常,但是.feature文件中出現一個小的警告。
下面,我將.feature文件中的整數傳遞到單獨的Java類的“步驟定義”中
在我的.feature文件的以下步驟下,出現一條黃色的波浪線:
Then the status code should be <StatusCode>
我收到的警告消息是:
未找到
the status code should be
定義
這是我的功能文件示例表:
| StatusCode |
| 200 |
以下是我的步驟定義:
@Then("^the status code should be (\\d+)$")
此錯誤使我無法按Ctrl +單擊 “ 那么 ”語句,以使我進入我的java類中的上述“步驟定義”。
有人對可能出什么問題有任何建議嗎?
也許這不是您應該通過示例表傳遞整數的方式
匹配step方法的regexp必須與step中的文本匹配(字面上)。
如果您的步驟是
Then the status code should be <StatusCode>
您的粘合代碼中的正則表達式
@Then("^the status code should be (\\d+)$")
將不匹配(因此您無法CTRL +單擊它) StatusCode
。
以下簡單的示例將起作用。
Scenario Outline: outline
Given something
Then the status code should be <StatusCode>
Examples:
| StatusCode |
| 200 |
和鏈接的步驟定義
@Then("^the status code should be ([^\"]*)$")
public void theStatusCodeShouldBe(String statusCode) throws Throwable {
...
}
編輯如果要將狀態代碼傳遞為Integer
,則可以將步驟定義的簽名更改為
@Then("^the status code should be ([^\"]*)$")
public void theStatusCodeShouldBe(Integer statusCode) throws Throwable {
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.