未定义步骤参考-Intellij Java [英] Undefined Step Reference - Intellij Java

查看:132
本文介绍了未定义步骤参考-Intellij Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我正在用Cucumber和Java创建一个测试自动化框架.我能够创建步骤定义并启动测试.但是,在Intellij的Gherkin功能中,总是向我表明该步骤没有被确认.因此,我无法导航到已实现的步骤定义.

Well, I am creating a test automation framework with Cucumber and Java. I am able to create the step definitions and launch the tests. However, in my Gherkin feature in Intellij, it always show's me that the step is not recongised. Because of this, I cannot navigate to the implemented step definition.

我确实尝试过遇到Stackoverflow的所有解决方案

I literally tried every solution that I came across Stackoverflow

//POM.xml-我的所有依赖项都在此文件中,以支持我的解决方案.我使用了Maven存储库中所有依赖项的最新版本

// POM.xml - All my dependencies are in this file that are needed to support my solution. I used the latest version of all dependencies from the Maven repository

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>execute_auto</groupId>
    <artifactId>execute_auto</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>4.7.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>4.5.3</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>gherkin</artifactId>
            <version>5.0.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm-deps -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.6</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>

        <!-- Web driver manager dependency -->

        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.6.2</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

//StepDefinition.java-这是获取提取的步骤定义的地方,该定义在运行测试时出现在控制台上

// StepDefinition.java - This is where I get the extracted step definitions which appear on the console when I run my test

package Steps;
import io.cucumber.java.en.*; //I replaced cucumber.api.java.
import Pages.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public class MyStepdefs {


    @Given("The user login to the application")
    public void the_user_login_to_the_application() {
        LoginPage login = new LoginPage(driver);
    }

    @When("the credentials are entered")
    public void the_credentials_are_entered() {
        // Write code here that turns the phrase above into concrete actions
        System.out.println("Print when steps");
    }

    @Then("the homepage is viewed")
    public void the_homepage_is_viewed() {
        // Write code here that turns the phrase above into concrete actions
        System.out.println("print then steps");
    }
}

//Myfeature-这是我用来自动化测试用例的示例功能

// Myfeature - this is the sample feature that I am using to automate my test case

Feature: LoginFeature
Scenario: Log in
Given The user login to the application
When the credentials are entered
Then the homepage is viewed

推荐答案

这是因为Intellij希望您先进行一些配置,然后才能自动选择步骤"定义. 链接将向您显示所需的分步设置过程(即您还没有看到).当我在Intellij中运行我的第一个黄瓜功能文件时,我遇到了同样的问题.同样在它起作用之后,您可以做一些其他的调整,这些调整我在此链接.

That's because, Intellij expects you to do some configurations before it'll automatically pick up your Step definitions. This link will the show you step by step setup process you need (That's if you've not already seen it). I had the same issue when I ran my first cucumber feature file in Intellij. Also after it works, you can do some more tweaks which I showed in this link.

这篇关于未定义步骤参考-Intellij Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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