簡體   English   中英

Cucumber 沒有運行我的 Step 定義文件 (java)

[英]Cucumber is not running my Step definition file (java)

當我運行我的測試運行器時,黃瓜會生成一個缺失的步驟,盡管我已經在我的 Test_Steps 類中實現了這些步驟。 我可以使用 Eclipse 中的“查找步驟”從功能文件導航到 Test_Steps 類。 請幫忙。 非常感謝

黃瓜跑者:

@RunWith(Cucumber.class)
@CucumberOptions(
    format = { "pretty","html: cucumber-html-reports",
               "json: cucumber-html-reports/cucumber.json" },
    features = {"src/features"},
    glue ={"src/features"}
)

public class CucumberRunner {

}

第一.特征:

Feature: Login Action

  Scenario: Successful Login with Valid Credentials    
    Given User opened STM
    When User in LogIn Page
   Then Message displayed Login Successfully

Test_Steps(StepDefinition 文件):

public class Test_Steps {

    public WebDriver driver ;

    @Given("^User opened STM$")
    public void User_opened_STM() throws Throwable {
        // Express the Regexp above with the code you wish you had
        driver= new FirefoxDriver();
        //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://10.100.2.127:9000/");
    }

    @When("^User in LogIn Page$")
    public void User_in_LogIn_Page() throws Throwable {
        // Express the Regexp above with the code you wish you had
        driver.findElement(By.id("input_login_password")).click();
        driver.findElement(By.id("input_login_username")).sendKeys("admin"); 
        driver.findElement(By.id("input_login_password")).sendKeys("");
        driver.findElement(By.xpath("html/body/form/div[1]/div/div[2]/button")).click();
    }


    @Then("^Message displayed Login Successfully$")
    public void Message_displayed_Login_Successfully() throws Throwable {
        // Express the Regexp above with the code you wish you had
        System.out.println("Login Successfully");  
    }

文件夾結構:所有包都在src文件夾下

功能文件:/src/features/first.feature 步驟定義文件:/src/features/Test_Steps.java

控制台輸出:

Feature: Login Action

  Scenario: Successful Login with Valid Credentials [90m# first.feature:3[0m
    [33mGiven [0m[33mUser opened STM[0m
    [33mWhen [0m[33mUser in LogIn Page[0m
    [33mThen [0m[33mMessage displayed Login Successfully[0m

1 Scenarios ([33m1 undefined[0m)
3 Steps ([33m3 undefined[0m)
0m0.000s

您可以使用以下代碼段實現缺失的步驟:

@Given("^User opened STM$")
public void User_opened_STM() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

@When("^User in LogIn Page$")
public void User_in_LogIn_Page() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

@Then("^Message displayed Login Successfully$")
public void Message_displayed_Login_Successfully() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

@CucumberOptions#glue屬性(我承認記錄不佳)應該指向您的步驟所在的 否則,Cucumber 將在與CucumberRunner類相同的包中查找步驟。

說了這么多,再說兩點:

  • 確保您的類在命名包中,而不是在“默認”中。 未命名的包。 只是為了讓事情更容易
  • 當您運行CucumberRunner時,請確保步驟實際上已編譯並位於類路徑上

暫無
暫無

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

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