运行测试时黄瓜异常



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

返回以下错误:

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. 步骤定义类
  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 类,不能包含黄瓜步骤定义注释。(这就是运行器类不能是步骤定义类的原因(。但是,您可以在此类中包含 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();
}
}

希望这对您有所帮助!

最新更新