如何使用 Cucumber 的测试运行器文件运行测试?
rest assureddynamic programmingprogramming
我们可以使用 Cucumber 的测试运行器文件运行测试。测试运行器文件应包含我们要执行的功能文件和步骤定义文件的路径。
功能文件的代码实现
功能 − 登录模块
场景 − 欢迎页面登录验证
假设用户位于欢迎页面
然后应显示欢迎页面
示例
步骤定义文件的代码实现
package stepDefinations; import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; public class stepDefination { @Given("^User is on Welcome Page$") public void user_on_welcome_page() { System.out.println("User on welcome page"); } @Then("^Welcome page should be displayed$") public void verify_user_on_welcome_page() { System.out.println("User should be on welcome page"); } }
Code Implementation of test runner file
package cucumberOptions; import org.junit.runner.RunWith; import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; @RunWith(Cucumber.class) @CucumberOptions( //功能文件路径 features = "src/test/java/features/Login.feature", //步骤定义文件路径 glue = "stepDefination" ) public class TestRunner { }