gpt4 book ai didi

java - cucumber 测试步骤在 J-Unit 中未显示,而在控制台步骤中已成功运行

转载 作者:行者123 更新时间:2023-12-02 09:52:00 25 4
gpt4 key购买 nike

我目前正在尝试创建我的第一个 Cucumber 测试。在 Java Eclipse 中,我创建了一个包含以下内容的“功能文件”:

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

我还创建了以下测试运行程序文件:

@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/Features/",
glue = {"Tests"}
)
public class CucumberRunner {
}

我还创建了我的步骤定义:

公共(public)类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)测试步骤似乎没有显示:

enter image description here

2) 当我双击功能/场景步骤时,我收到一条消息:

在所选项目中找不到测试类

阅读了有关此主题的其他一些帖子后,我的第一个想法是我的功能文件未位于正确的文件夹中,但我现在几乎已将其移动到任何地方,而且似乎没有任何区别。

这是我当前在 Eclipse 中的结构:

enter image description here

有人可以帮帮我吗?谢谢!

最佳答案

@CucumberOptions 中的答案 'junit = "--step-notifications"' 对我不起作用。但幸运的是,我立即找到了解决方案。

@CucumberOptions
(
features="path to feature file",

glue="path to step definition file",

stepNotifications = true
)

关于java - cucumber 测试步骤在 J-Unit 中未显示,而在控制台步骤中已成功运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56257912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com