我正在开发我的第一个功能文件/selenium 项目。
我创建了一个功能文件和运行器类。
package cucumberpkg2;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions
(features="Features")
public class Runner {
}
I have the feature file test.feature
Feature: Login screen
Scenario Outline: 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
但每当我尝试将 TestRunner 类作为 JUnit 测试运行时,都会收到错误:
在所选项目中找不到测试类。
这是您问题的解决方案:
- 根据当前的文档Cucumber https://cucumber.io/docs/reference您可能需要更改关键字
Scenario Outline
to Scenario
in test.feature
file.
- 虽然你提到过
TestRunner
类,但你的代码谈到Runner
类被实现为public class Runner
,确定您正在执行哪个类文件JUnit test
.
- 您可能需要改变
@CucumberOptions
to @Cucumber.Options
对于以前的版本(最近的版本适用于@CucumberOptions
)
- 将以下 2 部分放在一行中:
@Cucumber.Options
(features="Features")
- 正如你会提到的
@Cucumber.Options(features="Features")
确保您的功能文件放置在里面Features
项目目录中的子目录。
-
所以你将会拥有,test.feature
文件内Features
子目录包含以下代码:
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
-
Your 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
黄瓜的选项。
如果这能回答您的问题,请告诉我。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)