Search code examples
javacucumbertestngfeature-file

Why is my .feature file saying "Undefined step reference", although my cucumber tests run fine and detect the steps?


Intellij is saying my step is undefined when I'm looking at the .feature file.

Intellij undefined step

But the cucumber .feature file runs fine, and it is definitely matching on the step.

My TestNG runner code:

package package1;

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;

@CucumberOptions(plugin = "pretty", features = "src/test/resources/package1", glue = "package1")
public class Runner extends AbstractTestNGCucumberTests {

    @Override
    @DataProvider(parallel = true)
    public Object[][] scenarios() {
        return super.scenarios();
    }

}

The step in the feature file:

Feature: test feature
  Scenario: test feature scenario
  Given there has been a pebkac

My step in the StepDefinitions file:

Given("there has been a pebkac", () -> {
            //driver.findElement(By.id("editTextFieldId")).sendKeys("test");
            autoTools.getElement(new String[]{"editTextFieldId", "IOSIDHERE"}, AutomationTools.IdType.DEFAULT, 15).sendKeys("test");
            System.out.format("test: %n\n");

            //throw new cucumber.api.PendingException();
        });

Why is intellij complaining that it can't find this step? I tried using the step definition file with annotations instead and ran into the same issue.

I notice though that if I go to the feature file and right click -> add step, it will add a step using a deprecated Given method. This makes me feel like I may be using the wrong dependencies, though I got them from the cucumber tutorial on their website.

My dependencies:

dependencies {
    testImplementation 'io.cucumber:cucumber-java:4.7.4'

    compile group: 'org.testng', name: 'testng', version: '6.14.3'
    compile group: 'io.cucumber', name: 'cucumber-testng', version: '4.7.4'
    compile group: 'io.appium', name: 'java-client', version: '7.1.0'
}


Solution

  • Intellij was out of date, updating it resolved this problem.

    Reference: https://sqa.stackexchange.com/q/40044