Home > Back-end >  Selenium (Eclipse) - feature file - step is not highlighted if step definition is undefined
Selenium (Eclipse) - feature file - step is not highlighted if step definition is undefined

Time:11-01

I am very new to Selenium and Cucumber. I am asking for your kind advice. My problem is: Feature file - step is not highlighted, not showing warning messages if step definition is undefined.

My Feature file:

[![enter image description here][1]][1]

My runner:

[![enter image description here][2]][2]

Maven dependencies:

[![enter image description here][3]][3]

My pom.xml:

<?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>linkedlearning</groupId>
  <artifactId>Mycucumbercourse</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <name>Mycucumbercourse</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <junit.version>4.11</junit.version>
    <cucumber.version>4.2.5</cucumber.version>
    <maven.compiler.version>3.3</maven.compiler.version>  
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        
        <!-- hamcrest dependency required in order to be able to run test using maven (command: mvn test) -->
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest</artifactId>
            <version>2.2</version>
            <scope>test</scope>
        </dependency>
  
    </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

I tried to investigate myself and find that import io.cucumber.junit.CucumberOptions; in combination with stepNotifications = true may help. However when I try to add it I am getting: "The import io.cucumber.junit cannot be resolved". Looking forward for your kind advice. [1]: https://i.stack.imgur.com/KcrQN.png [2]: https://i.stack.imgur.com/t2h9a.png [3]: https://i.stack.imgur.com/n2gFr.png

CodePudding user response:

I found an answer here: Step Definition detection only works when project is configured as cucumber project.- Virtual Machine

Generally speaking: If the step definition is not happened and the feature file does not highlight undefined steps with amber color that means that the project is not converted as a cucumber project. Do the following:

  1. In order to convert the project as a cucumber project do the following: Right-click on your project from the Project Explorer > Configure > Convert as Cucumber Project.

  2. Ensure option Enable Step Definitions Glue Detection is checked in Window > Preferences > Cucumber

  • Related