Java 测试未运行
我正在进行我的第一个功能文件/selenium项目 我已经创建了一个功能文件和runner类Java 测试未运行,java,selenium,cucumber,Java,Selenium,Cucumber,我正在进行我的第一个功能文件/selenium项目 我已经创建了一个功能文件和runner类 包装黄瓜pkg2; 导入org.junit.runner.RunWith; 进口cucumber.api.CucumberOptions; 进口cucumber.api.junit.cucumber; @RunWith(cumber.class) @黄瓜选项 (features=“features”) 公开课跑者{ }您需要提供功能文件的完整路径,如下所述 @RunWith(Cucumber.clas
包装黄瓜pkg2;
导入org.junit.runner.RunWith;
进口cucumber.api.CucumberOptions;
进口cucumber.api.junit.cucumber;
@RunWith(cumber.class)
@黄瓜选项
(features=“features”)
公开课跑者{
}
您需要提供功能文件的完整路径,如下所述
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/test/resources/com/gaurang/steps/demo.feature",
"src/test/resources/com/gaurang/steps/demo1.feature"
}
)
public class RunAllTest {
}
或者,如果功能文件太多,最好的方法是向功能文件提供标记,然后使用这些标记运行,如下所述
@userRegistrations
Feature: User Registration
RunAllTest.java
@RunWith(Cucumber.class)
@CucumberOptions(tags={"@userRegistrations"})
public class RunAllTest {
}
您可以使用多个标签以下是您问题的解决方案:
test.feature
文件中的关键字Scenario Outline
更改为Scenario
TestRunner
类,但您的代码提到了Runner
类被实现为public class Runner
,请确保您作为JUnit test
执行的是哪个类文件@CucumberOptions
更改为@Cucumber.Options
(最新版本使用@cucucumberoptions
)@Cucumber.Options放在一行中
(features=“features”)
@Cucumber.Options(features=“features”)
确保您的功能文件位于项目目录中的features
子目录中Features
子目录中拥有,test.feature
文件,其中包含以下代码:
Feature: Login screen
Scenario: Successful login
Given User is on Login page
When User enters valid UserName and Password
And Clicks the login button
Then User landed on the home page
Runner
课程将如下所示:
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features="Features")
public class Runner {
}
Runner
类作为JUnit测试时,您将在控制台上看到以下消息:
You can implement missing steps with the snippets below:
@Given("^User is on Login page$")
public void User_is_on_Login_page() throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
@When("^User enters valid UserName and Password$")
public void User_enters_valid_UserName_and_Password() throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
@When("^Clicks the login button$")
public void Clicks_the_login_button() throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
@Then("^User landed on the home page$")
public void User_landed_on_the_home_page() throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
glue
选项应用于Cucumber,可以轻松处理这些警告如果这回答了您的问题,请告诉我。您还需要指定glue作为功能文件的步骤定义驻留的位置,如
glue={“packagename.classname”},
in@CucumberOptions@kushal. <代码>粘合选项不是测试Cucumber项目绑定的必需选项。但是当您想要测试完整的实现时,glue
是必需的:)Thanks@dev,我知道glue有时不是强制性的,但我不理解您的陈述:/n如果您的资源文件中的结构与java中的结构相同,那么这些特性的实现就不需要glue陈述,否则您需要它。您的解决方案将只处理demo.feature
(一个)功能文件,如果您有多个功能文件,该怎么办:)@Dev i获取多个功能文件,我已更新了答案。不过,最好使用标记。为功能提供标记,然后使用它们。是的,你是对的:)我宁愿传递包含这些功能的文件夹的名称