首页 文章

我的第一个基本Cucumber程序(Scenario)失败了 - Java

提问于
浏览
1

我今天写了我的第一个Cucumber程序,它失败了 . 我写了一个非常基本的,一个简单的场景,它是步骤定义 . 以下是功能文件代码和步骤定义代码 .

步骤定义代码:

import cucumber.api.java.en.When;
    import cucumber.api.java.en.Then;

    public class Testing_Example1 {

           @When("^I am on x page$")
           public void i_am_on_x_page() throws Throwable {

              System.out.println("I am on xPage");

           }

           @Then("^I see that element$")
           public void i_see_that_element() throws Throwable {

               System.out.println("I can see that page");
           }
    }

特征文件代码:

Feature: Testing
     Scenario: s1
      When I am on x page
      Then I see that element

我也添加了系统变量 - JAVA_HOME和maven变量,并将其链接到PATH变量I系统变量 .

我已经在POM文件中添加了依赖项,例如Cucumber-Java,Cucumber-Junit以及selenium,但我的程序失败并且说步骤未定义 .

输出:

1 Scenarios (1 undefined)
    2 Steps (2 undefined)0m0.000s


    You can implement missing steps with the snippets below:
    @When("^I am on x page$")
    public void i_am_on_x_page() throws Throwable {
   // Write code here that turns the phrase above into concrete     actions
   throw new PendingException();
   }

   @Then("^I see that element$")
   public void i_see_that_element() throws Throwable {
   // Write code here that turns the phrase above into concrete actions    
  throw new PendingException();
  }

   Undefined step: When  I am on x page

   Undefined step: Then  I see that element

   Process finished with exit code 0

我想这是因为我的功能文件没有与步骤定义文件链接,但我不明白缺少的是功能文件没有正确执行和方案失败 . 有这方面知识的人会帮忙 .

谢谢!

2 回答

  • 0

    我找到了解决方案 . 我刚编辑了功能文件的配置 - >编辑配置 - >粘贴步骤定义文件所在的包的路径 - > apply .

    我只需要使用Glue将特征文件链接到步骤定义 .

  • 1

    在yellow runner runner类中指定stepdefintion和feature文件详细信息 .

    @CucumberOptions(
                    plugin={"pretty", "html:target/cucumber-html-report","json:target/cucumber-report.json"},
                    features = "src/test/resources",
                    glue ="com.vg.pw.ui.stepdefinitions",
    
                    )
    public class CucumberRunner  {
    
        ...
    }
    

相关问题