當我從 IntelliJ IDE 中運行 cucumber 測驗時,它可以完美運行。
然而,當我試圖從命令提示符中運行它時,在創建一個運行器類之后,步驟定義沒有被識別。
下面是代碼的樣子:
import io.cucumber.junit.Cucumber。
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
glue={"classpath:src estjava"},
features = "src est
esources",
plugin={"pretty", "html:target/site/cucumber-pretty", "json:target/cucumber.json" })
public class RunCucumberTests {
}
下面是專案結構的樣子。LoginSeps "類包含了步驟的定義。
被拋出的錯誤如下
[ERROR] 測驗運行。5, 失敗。0, 錯誤。5, Skipped: 0, Time elapsed: 0.79 s <<< FAILURE! - in RunCucumberTests [ERROR] Login functionality.Login Successful Time elapsed: 0.276 s <<< ERROR! io.cucumber.junit.UndefinedStepException。 I am in the login page of application' and 2 other step(s) are undefined.....如果有任何幫助,我們將不勝感激。
uj5u.com熱心網友回復:
Stepdefiniton類應該總是存在于一個包中,并且在src estjava檔案夾下。
請創建一個cucumberStep包或其他東西,并將LoginSteps類移至該包下。
代碼:
@CucumberOptions(features = "src est
esourcesfeatures", glue = { "cucumberStep", }, dryRun = false, plugin = { "pretty",
"html:report/TestReport.html", }, monochrome = true, stepNotifications = true, tags = "@Regression")
uj5u.com熱心網友回復:
這個問題通過一些重構得到了解決。
將步驟定義類移到一個新的包中,并在膠水中參考包的名稱,解決了這個問題。
下面是解決方案現在的樣子。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/309737.html
標籤:

