【问题标题】:Cucumber exception when run the test运行测试时黄瓜异常
【发布时间】:2020-03-28 15:35:23
【问题描述】:

我有一个我认为很愚蠢的问题...... 我无法对黄瓜进行测试。

返回以下错误:

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

有人可以帮忙吗?

谢谢!!

【问题讨论】:

    标签: java selenium automation automated-tests cucumber


    【解决方案1】:

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

    1. 步骤定义类
    2. 功能类
    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*/
          }
    
         }
    

    3.跑者班

    跑步者类由特征的位置和步骤定义组成。它是一个 Junit 类,不能包含黄瓜步骤定义注释。 (这就是 runner 类不能是步骤定义类的原因)。但是,您可以在此类中包含 BeforeClass、AfterClass(Junit 注释)

     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();
       }
    }
    

    希望对你有帮助!

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 2019-12-06
    • 2017-10-13
    • 1970-01-01
    • 2020-12-19
    相关资源
    最近更新 更多