0
votes

I am working on Selenium with Cucumber setup and I am facing error when I run the TestRunner file.

cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.

POM.xml

<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>Automation</groupId>
  <artifactId>Cucumber</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>Cucumber</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.5</version>

</dependency>


<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
</dependency>


    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>      
    </dependency>
  </dependencies>
</project>

I have mapped feature file to StepDefinition file as shown below Feature file Feature: Login Functionality

Scenario: Home page default login Given User is on Home page When User logs into application with valid credentials Then User should be logged into application and landing page should be displayed to user

StepDefinition file

package stepDefenition;

import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;
import cucumber.api.java.en.Then;

@RunWith(Cucumber.class)
public class StepDefenition {

    @Given("^User is on Home page$")
    public void user_is_on_home_page() throws Throwable {
        System.out.println("User is on Home Page");
    }

    @When("^User logs into application with valid credentials$")
    public void user_logs_into_application_with_valid_credentials() throws Throwable {
        System.out.println("User enters valid credentials and clicks on submit");

    }

    @Then("^User should be logged into application and landing page should be displayed to user$")
    public void user_should_be_logged_into_application_and_landing_page_should_be_displayed_to_user() throws Throwable {
         System.out.println("User logged in successfully and landing page is displayed to user  with all the details");
    }

}

Test Runner File:

package cucumberOption;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/java/features",
        glue="stepDefenition")

public class TestRunner {   

}

I am using version:

  • Neon.3 Release (4.6.3) of Eclipse
  • Natural 0.7.6 Cucumber plugin
  • Maven version : Apache Maven 3.6.3
  • Java Version : java version "1.8.0_241"

structure of the project

Project Structure

I have tried changing versions for java and Junit and adding Io.cucumber dependencies nothing worked.

Added java 1.8 jdk to project build path.

I have viewed all previous threads on this kind of issue.

1
There are many problems with your project. Consider starting from scratch with cucumber.io/docs/guides/10-minute-tutorial - M.P. Korstanje

1 Answers

0
votes

I did not understand why you using @RunWith annotation in step def class. As cucumber will automatically take care of running it via cucumberRunner, so you can execute your test either from Runner class or via feature files(Scenario level or entire feature file) w/o using any @RunWith annotation. Probably this is the cause of your error here-See below exception:

cucumber.runtime.CucumberException:

Classes annotated with @RunWith(Cucumber.class) must not define any Step Definition or Hook methods. Their sole purpose is to serve as an entry point for JUnit. Step Definitions and Hooks should be defined in their own classes. This allows them to be reused across features. Offending class: class com.abc.StepDefs.FWFeatureTestSteps (for ex).

Also you need not to have separate junit dependency in pom, only cucumber-junit is enough as long as you want cucumber to get the job done. Note: Don't mix io.cucumber and info.cukes, use any of them. Mixing both will also cause this very same exception.