Java 运行测试时出现异常

Java 运行测试时出现异常,java,selenium,automation,automated-tests,cucumber,Java,Selenium,Automation,Automated Tests,Cucumber,我有一个问题,我认为是愚蠢的。。。 我不能用黄瓜做测试 返回以下错误: cucumber.runtime.CucumberException: Classes annotated with @RunWith(Cucumber.class) must not define any Step Definition or Hook methods. Their sole purpose is to serve as an entry point for JUnit. Step Definition

我有一个问题,我认为是愚蠢的。。。 我不能用黄瓜做测试

返回以下错误:

cucumber.runtime.CucumberException: 

Classes annotated with @RunWith(Cucumber.class) must not define any
Step Definition or Hook methods. Their sole purpose is to serve as
an entry point for JUnit. Step Definitions and Hooks should be defined
in their own classes. This allows them to be reused across features.
Offending class: class Teste.testecucumber
有人能帮忙吗


谢谢

@Runwith在Cucumber项目的TestRunner类中声明。Cucumber项目定义了3种类型的类:

  • 步骤定义类
  • 要素类
  • 跑步班
  • 请查找上述课程的以下示例:

    1。要素类

    测试用例是在这个类中编写的

       Feature: Title of your feature
       I want to use this template for my feature file
    
       @tag1
       Scenario: Verify login to the system.
       Given I navigate to url
       And I enter username as "username"
       And I enter password as "password"
       When I click Login
       Then I should be logged into the system
    
    2。步骤定义类

    特征步骤在此类中定义

        public class LoginPage(){
    
         @Given("I navigate to the url")
         public void navigate() {
    
            /* your code for the above 
            step comes here*/
          }
    
         }
    
     import org.junit.runner.RunWith;
     import cucumber.api.CucumberOptions;
     import cucumber.api.junit.Cucumber;
    
     @RunWith(Cucumber.class)
     @CucumberOptions( 
     features = {"classpath:<location of your folder with feature classes / package name>"},
     glue = {"<package name>" },
     tags = { "<the tags that has to be executed>","can be comma separated multiple tags" }
     )
    
    
    
     public class testrunner {
    
       //@AfterClass
       public static void quitDriver() {
        driver.quit();
       }
    }
    
    3。跑步者等级

    runner类由特征的位置和步骤定义组成。它是Junit类,不能包含cucumber步骤定义注释。(这就是为什么runner类不能是步骤定义类的原因)。但是,您可以在这个类中包括BeforeClass、AfterClass(Junit注释)

        public class LoginPage(){
    
         @Given("I navigate to the url")
         public void navigate() {
    
            /* your code for the above 
            step comes here*/
          }
    
         }
    
     import org.junit.runner.RunWith;
     import cucumber.api.CucumberOptions;
     import cucumber.api.junit.Cucumber;
    
     @RunWith(Cucumber.class)
     @CucumberOptions( 
     features = {"classpath:<location of your folder with feature classes / package name>"},
     glue = {"<package name>" },
     tags = { "<the tags that has to be executed>","can be comma separated multiple tags" }
     )
    
    
    
     public class testrunner {
    
       //@AfterClass
       public static void quitDriver() {
        driver.quit();
       }
    }
    
    import org.junit.runner.RunWith;
    进口cucumber.api.CucumberOptions;
    进口cucumber.api.junit.cucumber;
    @RunWith(cumber.class)
    @黄瓜选项(
    功能={“类路径:”},
    glue={“},
    标记={“”“可以是逗号分隔的多个标记”}
    )
    公共类测试运行程序{
    //@下课
    公共静态驱动程序(){
    driver.quit();
    }
    }
    

    希望这对你有帮助

    @Runwith在Cucumber项目的TestRunner类中声明。Cucumber项目定义了3种类型的类:

  • 步骤定义类
  • 要素类
  • 跑步班
  • 请查找上述课程的以下示例:

    1。要素类

    测试用例是在这个类中编写的

       Feature: Title of your feature
       I want to use this template for my feature file
    
       @tag1
       Scenario: Verify login to the system.
       Given I navigate to url
       And I enter username as "username"
       And I enter password as "password"
       When I click Login
       Then I should be logged into the system
    
    2。步骤定义类

    特征步骤在此类中定义

        public class LoginPage(){
    
         @Given("I navigate to the url")
         public void navigate() {
    
            /* your code for the above 
            step comes here*/
          }
    
         }
    
     import org.junit.runner.RunWith;
     import cucumber.api.CucumberOptions;
     import cucumber.api.junit.Cucumber;
    
     @RunWith(Cucumber.class)
     @CucumberOptions( 
     features = {"classpath:<location of your folder with feature classes / package name>"},
     glue = {"<package name>" },
     tags = { "<the tags that has to be executed>","can be comma separated multiple tags" }
     )
    
    
    
     public class testrunner {
    
       //@AfterClass
       public static void quitDriver() {
        driver.quit();
       }
    }
    
    3。跑步者等级

    runner类由特征的位置和步骤定义组成。它是Junit类,不能包含cucumber步骤定义注释。(这就是为什么runner类不能是步骤定义类的原因)。但是,您可以在这个类中包括BeforeClass、AfterClass(Junit注释)

        public class LoginPage(){
    
         @Given("I navigate to the url")
         public void navigate() {
    
            /* your code for the above 
            step comes here*/
          }
    
         }
    
     import org.junit.runner.RunWith;
     import cucumber.api.CucumberOptions;
     import cucumber.api.junit.Cucumber;
    
     @RunWith(Cucumber.class)
     @CucumberOptions( 
     features = {"classpath:<location of your folder with feature classes / package name>"},
     glue = {"<package name>" },
     tags = { "<the tags that has to be executed>","can be comma separated multiple tags" }
     )
    
    
    
     public class testrunner {
    
       //@AfterClass
       public static void quitDriver() {
        driver.quit();
       }
    }
    
    import org.junit.runner.RunWith;
    进口cucumber.api.CucumberOptions;
    进口cucumber.api.junit.cucumber;
    @RunWith(cumber.class)
    @黄瓜选项(
    功能={“类路径:”},
    glue={“},
    标记={“”“可以是逗号分隔的多个标记”}
    )
    公共类测试运行程序{
    //@下课
    公共静态驱动程序(){
    driver.quit();
    }
    }
    

    希望这对你有帮助

    glue
    应该是包名,而不是目录。所以
    com.example.app
    .True。如果它只是项目中的一个包,则可以仅使用包名;如果步骤定义位于深层文件夹结构中,则可以使用文件夹的路径。参考,自v4.2.3以来,建议使用软件包名称:谢谢。我已经根据信息更新了答案
    glue
    应该是一个包名,而不是目录。所以
    com.example.app
    .True。如果它只是项目中的一个包,则可以仅使用包名;如果步骤定义位于深层文件夹结构中,则可以使用文件夹的路径。参考,自v4.2.3以来,建议使用软件包名称:谢谢。我已经根据信息更新了答案