繁体   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