[英]Cucumber test not running
我正在研究我的第一個特征文件/ selenium項目。
我創建了一個功能文件和跑步者類。
package cucumberpkg2; import org.junit.runner.RunWith; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; @RunWith(Cucumber.class) @CucumberOptions (features="Features") public class Runner { }
Feature: Login screen Scenario Outline: Successful login Given User is on Login page When User enters valid UserName and Password And Clicks the login button Then User landed on the home page
但每當我嘗試將TestRunner類作為JUnit測試運行時,我都會收到錯誤:
在所選項目中找不到測試類。
以下是您的問題的解決方案:
test.feature
文件中將關鍵字Scenario Outline
更改為Scenario
。 TestRunner
類,但是你的代碼講的是Runner
類被實現為public class Runner
,但是要確保你作為JUnit test
執行哪個類文件。 @CucumberOptions
更改為@Cucumber.Options
(最新版本適用於@CucumberOptions
) @Cucumber.Options (features="Features")
@Cucumber.Options(features="Features")
確保您的要素文件放在項目目錄中的Features
子目錄中。 因此,您將在Features
子目錄中使用以下代碼獲得test.feature
文件:
Feature: Login screen Scenario: Successful login Given User is on Login page When User enters valid UserName and Password And Clicks the login button Then User landed on the home page
你的Runner
類看起來像:
import org.junit.runner.RunWith; import cucumber.api.junit.Cucumber; @RunWith(Cucumber.class) @CucumberOptions(features="Features") public class Runner { }
最后,當您將Runner
類作為JUnit測試執行時,您將在控制台上看到以下消息:
You can implement missing steps with the snippets below: @Given("^User is on Login page$") public void User_is_on_Login_page() throws Throwable { // Express the Regexp above with the code you wish you had throw new PendingException(); } @When("^User enters valid UserName and Password$") public void User_enters_valid_UserName_and_Password() throws Throwable { // Express the Regexp above with the code you wish you had throw new PendingException(); } @When("^Clicks the login button$") public void Clicks_the_login_button() throws Throwable { // Express the Regexp above with the code you wish you had throw new PendingException(); } @Then("^User landed on the home page$") public void User_landed_on_the_home_page() throws Throwable { // Express the Regexp above with the code you wish you had throw new PendingException(); }
通過為Cucumber實施glue
選項,可以輕松地注意這些警告。
如果這回答你的問題,請告訴我。
您需要提供功能文件的完整路徑,如下所述。
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/test/resources/com/gaurang/steps/demo.feature",
"src/test/resources/com/gaurang/steps/demo1.feature"
}
)
public class RunAllTest {
}
或者,如果您有太多的功能文件,最好的方法是為功能文件提供標簽,然后使用這些標簽運行,如下所述。
@userRegistrations
Feature: User Registration
RunAllTest.java
@RunWith(Cucumber.class)
@CucumberOptions(tags={"@userRegistrations"})
public class RunAllTest {
}
您可以使用多個標簽
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.