Cucumber 测试步骤未在 J-Unit 中显示,而在控制台步骤中已成功 运行
Cucumber Test steps not showing in J-Unit while in console steps have run successfully
我目前正在尝试创建我的第一个 Cucumber 测试。在 Java Eclipse 中,我创建了一个包含以下内容的 'Feature file':
Feature: Login functionality DemoQA.com
Scenario: Verify if user is able to login to the DemoQA website
Given A user is on DemoQA.com
When User clicks MyAccount link
Then User is taken to Login Page
When User enters valid username and password
Then User is able to login
我还创建了以下测试运行ner 文件:
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/Features/",
glue = {"Tests"}
)
public class CucumberRunner {
}
我还创建了步骤定义:
public class LoginStepDefinitions {
@Given("A user is on DemoQA.com")
public void a_user_is_on_DemoQA_com() {
System.setProperty("webdriver.gecko.driver","C:\geckodriver-v0.10.0-win64\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 50);
String url = "https://demoqa.com";
//Launch the Online Store Website
driver.get(url);
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"logo-events\"]/a/img")));
driver.findElement(By.xpath("//*[@id=\"logo-events\"]/a/img"));
System.out.println("User has succesfully opened DemoQA.com");
}
catch (Exception e) {
System.out.println("User was not able to open DemoQA.com");
}
}
@When("User clicks MyAccount link")
public void user_clicks_MyAccount_link() {
// Write code here that turns the phrase above into concrete actions
System.out.println("User clicks on the MyAccount link");
}
@Then("User is taken to Login Page")
public void user_is_taken_to_Login_Page() {
System.out.println("User is succesfully taken to MyAccount login");
}
@When("User enters valid username and password")
public void user_enters_valid_username_and_password() {
System.out.println("User enters valid credentials for MyAccount login");
}
@Then("User is able to login")
public void user_is_able_to_login() {
// Write code here that turns the phrase above into concrete actions
System.out.println("User is succesfully logged in");
}
}
当我运行我的脚本作为Junit测试时,控制台成功执行测试并显示结果:
User has succesfully opened DemoQA.com
[32m.[0mUser clicks on the MyAccount link
[32m.[0mUser is succesfully taken to MyAccount login
[32m.[0mUser enters valid credentials for MyAccount login
[32m.[0mUser is succesfully logged in
[32m.[0m
1 Scenarios ([32m1 passed[0m)
5 Steps ([32m5 passed[0m)
0m7.706s
但是当打开 JUnit 选项卡时会发生两件事:
1) 似乎没有显示测试步骤:
2) 当我双击功能/场景步骤时,我收到一条消息:
未在所选项目中找到测试Class
阅读了有关此主题的其他一些帖子后,我的第一个想法是我的功能文件不在正确的文件夹中,但我现在几乎已将其移动到任何地方,这似乎没有任何区别。
这是我在 Eclipse 中的当前结构:
有人可以帮帮我吗?谢谢!
我通过在我的 Runner 文件的@cucumberoptions 中添加以下行自行解决了这个问题:junit = "--step-notifications"。在运行器文件中添加此行后,我的测试步骤也出现在 Junit 结果中。问题可以关闭
@CucumberOptions 中的答案 'junit = "--step-notifications"' 对我不起作用。但幸运的是,我立即找到了解决方案。
@CucumberOptions
(
features="path to feature file",
glue="path to step definition file",
stepNotifications = true
)
@CucumberOptions 中的 'junit = "--step-notifications"' 对我也不起作用。
我这样做了:
@CucumberOptions(
stepNotifications = true,
strict = true,
features="path to feature file",
glue="path to step definition file")
及其工作原理。我的测试步骤也出现在 Junit 结果中。
strict = true
-- 用于抑制 Waring :
此默认设置将更改为 --strict 并且 --non-strict 将被删除。
您可以使用 --strict 或 @CucumberOptions(strict = true) 来抑制此警告
在 TestRunner 中添加以下代码,您将看到启用的步骤通知。
@CucumberOptions(features="src/test/java/features", glue={"stepDefinitions"}, stepNotifications=true)
我目前正在尝试创建我的第一个 Cucumber 测试。在 Java Eclipse 中,我创建了一个包含以下内容的 'Feature file':
Feature: Login functionality DemoQA.com
Scenario: Verify if user is able to login to the DemoQA website
Given A user is on DemoQA.com
When User clicks MyAccount link
Then User is taken to Login Page
When User enters valid username and password
Then User is able to login
我还创建了以下测试运行ner 文件:
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/Features/",
glue = {"Tests"}
)
public class CucumberRunner {
}
我还创建了步骤定义:
public class LoginStepDefinitions {
@Given("A user is on DemoQA.com")
public void a_user_is_on_DemoQA_com() {
System.setProperty("webdriver.gecko.driver","C:\geckodriver-v0.10.0-win64\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 50);
String url = "https://demoqa.com";
//Launch the Online Store Website
driver.get(url);
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"logo-events\"]/a/img")));
driver.findElement(By.xpath("//*[@id=\"logo-events\"]/a/img"));
System.out.println("User has succesfully opened DemoQA.com");
}
catch (Exception e) {
System.out.println("User was not able to open DemoQA.com");
}
}
@When("User clicks MyAccount link")
public void user_clicks_MyAccount_link() {
// Write code here that turns the phrase above into concrete actions
System.out.println("User clicks on the MyAccount link");
}
@Then("User is taken to Login Page")
public void user_is_taken_to_Login_Page() {
System.out.println("User is succesfully taken to MyAccount login");
}
@When("User enters valid username and password")
public void user_enters_valid_username_and_password() {
System.out.println("User enters valid credentials for MyAccount login");
}
@Then("User is able to login")
public void user_is_able_to_login() {
// Write code here that turns the phrase above into concrete actions
System.out.println("User is succesfully logged in");
}
}
当我运行我的脚本作为Junit测试时,控制台成功执行测试并显示结果:
User has succesfully opened DemoQA.com
[32m.[0mUser clicks on the MyAccount link
[32m.[0mUser is succesfully taken to MyAccount login
[32m.[0mUser enters valid credentials for MyAccount login
[32m.[0mUser is succesfully logged in
[32m.[0m
1 Scenarios ([32m1 passed[0m)
5 Steps ([32m5 passed[0m)
0m7.706s
但是当打开 JUnit 选项卡时会发生两件事:
1) 似乎没有显示测试步骤:
2) 当我双击功能/场景步骤时,我收到一条消息:
未在所选项目中找到测试Class
阅读了有关此主题的其他一些帖子后,我的第一个想法是我的功能文件不在正确的文件夹中,但我现在几乎已将其移动到任何地方,这似乎没有任何区别。
这是我在 Eclipse 中的当前结构:
有人可以帮帮我吗?谢谢!
我通过在我的 Runner 文件的@cucumberoptions 中添加以下行自行解决了这个问题:junit = "--step-notifications"。在运行器文件中添加此行后,我的测试步骤也出现在 Junit 结果中。问题可以关闭
@CucumberOptions 中的答案 'junit = "--step-notifications"' 对我不起作用。但幸运的是,我立即找到了解决方案。
@CucumberOptions
(
features="path to feature file",
glue="path to step definition file",
stepNotifications = true
)
'junit = "--step-notifications"' 对我也不起作用。
我这样做了:
@CucumberOptions(
stepNotifications = true,
strict = true,
features="path to feature file",
glue="path to step definition file")
及其工作原理。我的测试步骤也出现在 Junit 结果中。
strict = true
-- 用于抑制 Waring :
此默认设置将更改为 --strict 并且 --non-strict 将被删除。 您可以使用 --strict 或 @CucumberOptions(strict = true) 来抑制此警告
在 TestRunner 中添加以下代码,您将看到启用的步骤通知。
@CucumberOptions(features="src/test/java/features", glue={"stepDefinitions"}, stepNotifications=true)