使用Cucumber JVM运行测试时出现UndefinedStepException [英] UndefinedStepException when run test using Cucumber JVM

查看:624
本文介绍了使用Cucumber JVM运行测试时出现UndefinedStepException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Cucumber + Junit + Appium开发了针对移动应用程序的测试.当我尝试使用黄瓜和JUnit运行器运行测试时,收到:io.cucumber.junit.UndefinedStepException: The step "I install the application" is undefined. You can implement it using the snippet(s) below:

I develop a test for the mobile application using 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:

我尝试了中型博客和堆栈问题中的一些解决方案,但这无济于事.

I tried some of the solutions from the medium blog and stack question, but this doesn't help.

我有一个项目结构:

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

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

LoginStep.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);
    }

}

缺少Login类的某些步骤,但这是因为我想将所有代码都放在问题上.

Some of the steps on the Login class is missing, but that is because I want to put all the code to the question.

我希望运行该功能,但实际上不起作用.

I expected to run that feature, but actually that is not work.

推荐答案

src.test.java通常不是软件包名称的一部分.尝试使用:

Typically src.test.java is not part of the package name. Try using:

glue = "com.mobile.automation.framework.stepDefinition",

并且由于Cucumber默认情况下会在Runners程序包中搜索胶水,因此也可以完全去除胶水.

And because Cucumber will search the runners package for glue by default can also remove the glue entirely.

这篇关于使用Cucumber JVM运行测试时出现UndefinedStepException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆