问题
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.
I literally tried every solution that I came across Stackoverflow
// 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 - 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 - 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
回答1:
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.
回答2:
This was fixed in the latest IntelliJ update:
https://youtrack.jetbrains.com/issue/IDEA-217391.
来源:https://stackoverflow.com/questions/57416690/undefined-step-reference-intellij-java