[英]UndefinedStepException when run test using Cucumber JVM
I develop a test for the mobile application using Cucumber+Junit+Appium.我使用 Cucumber+Junit+Appium 为移动应用程序开发了一个测试。 When I try to run a test using cucumber and JUnit runner I receive:
io.cucumber.junit.UndefinedStepException: The step "I install the application" is undefined. You can implement it using the snippet(s) below:
When I try to run a test using cucumber and JUnit runner I receive:
io.cucumber.junit.UndefinedStepException: The step "I install the application" is undefined. You can implement it using the snippet(s) below:
io.cucumber.junit.UndefinedStepException: The step "I install the application" is undefined. You can implement it using the snippet(s) below:
I tried some of the solutions from the medium blog and stack question, but this doesn't help.我尝试了一些来自媒体博客和堆栈问题的解决方案,但这并没有帮助。
I have a project structure:我有一个项目结构:
src
|-main
|--java
|---{project-name}
|----config
|----models
|----screens
|----services
|-test
|--java
|---{project-name}
|----helpers
|----stepDefinitions
|-----LoginStep.java
|-----BaseStep.java
|-----LoginStep.java
|----RunCucumber.java
|--resources
|---feature
|----Login.feature
RunCucumber.java RunCucumber.java
package com.mobile.automation.framework;
import com.google.inject.Guice;
import com.mobile.automation.framework.module.ServiceModules;
import com.mobile.automation.framework.service.AppiumServer;
import com.mobile.automation.framework.config.drivers.DriverFactory;
import com.mobile.automation.framework.module.ScreensModule;
import io.appium.java_client.AppiumDriver;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
strict = true,
monochrome = true,
glue = "src.test.java.com.mobile.automation.framework.stepDefinition",
features = "src/test/resources/feature",
plugin = {"pretty", "html:target/cucumber-report/cucumber.html",
"json:target/cucumber-report/cucumber.json",
"junit:target/cucumber-report/cucumber.xml"})
public class RunCucumber {
public static AppiumDriver driver;
@Before
public void setUpDriver() {
init();
new AppiumServer().startServer();
driver = new DriverFactory().getDriver();
}
@After
public void tearDownDriver() {
if (driver != null) {
driver.quit();
new AppiumServer().stopServer();
}
}
private void init() {
Guice.createInjector(
new ScreensModule(driver),
new ServiceModules(driver)
).injectMembers(this);
}
}
Login.feature登录功能
Feature: Sign In feature
Background:
Given I install application
And I enable all network activity
Then I am on Sign Page
Scenario: Sign In scenario
Given I am go to the Login Page
And I fill valid user data using "Config"
And I click sign in button
Then I am login in the application
LoginStep.java登录Step.java
package com.mobile.automation.framework.stepDefinition;
import javax.inject.Inject;
import com.mobile.automation.framework.config.ProjectConfig;
import com.mobile.automation.framework.models.User;
import com.mobile.automation.framework.screens.DashboardScreen;
import com.mobile.automation.framework.screens.SignInScreen;
import io.cucumber.java.ParameterType;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
/**
* @author Tomash Gombosh
*/
public class LoginStep {
@Inject
private SignInScreen signInScreen;
@Inject
private DashboardScreen dashboardScreen;
@Given("^I am go to the Login Page$")
public void iAmGoToTheLoginPage() {
dashboardScreen.tapLogin();
}
@And("I fill valid user data using {string} {string}")
public void iFillValidUserDataUsing(String userName, String password) {
signInScreen.fillLogin(userName, password);
}
@And("I fill valid user data using {string}")
@ParameterType("Config")
public void iFillValidUserDataUsing() {
signInScreen.fillLogin(new User(data -> {
data.setEmail(new ProjectConfig().getBaseUser());
data.setPassword(new ProjectConfig().getBaseUserPassword());
}));
}
@And("I click sign in button")
public void iClickSignInButton() {
signInScreen.clickLogin();
}
@Then("I am login in the application")
public void iAmLoginInTheApplication() {
assertThat(signInScreen.isDisplayed()).isEqualTo(true);
}
}
Some of the steps on the Login class is missing, but that is because I want to put all the code to the question.缺少登录 class 上的一些步骤,但那是因为我想将所有代码都放在问题中。
I expected to run that feature, but actually that is not work.我希望运行该功能,但实际上这是行不通的。
Typically src.test.java
is not part of the package name.通常
src.test.java
不是包名的一部分。 Try using:尝试使用:
glue = "com.mobile.automation.framework.stepDefinition",
And because Cucumber will search the runners package for glue by default can also remove the glue entirely.并且因为默认情况下 Cucumber 会在 runners 包中搜索胶水,所以也可以完全去除胶水。
New here myself working on Junit Runner, I agree with @MPKorstanje with classpath.新来的我自己在 Junit Runner 上工作,我同意 @MPKorstanje 的类路径。 Although I just had to change glue to refer the stepDefs with classpath too - wasn't getting recognized before.
虽然我只需要更改胶水来引用带有类路径的 stepDefs - 之前没有得到认可。
So basically this is what I did to catch the necessary files to be triggered所以基本上这就是我为捕获要触发的必要文件所做的事情
feature = { "classpath:path-from-repo-root.feature" },
glue = { "classpath:reference-to-stepDef-folder" }
Bear in mind: for glue - I used to the reference to the folder containing the stepDefs and not the stepDef file itself.请记住:对于胶水 - 我习惯于引用包含 stepDefs 的文件夹,而不是 stepDef 文件本身。 Hope this helps someone.
希望这可以帮助某人。 Thanks
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.