2

I have been playing around with Selenium Cucumber and came across this error message:

Type mismatch: Cannot convert from Class StepDefinition to Class?extends Runner

and here is my code:

package com.cucumber.JUnit;

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

import com.cucumber.steps.StepDefinition;

@RunWith(StepDefinition.class)
@CucumberOptions(
  format = { "pretty", "html:report/test-report" },
  features = { "src/test/resources/sample.feature" },
  glue = { "com.cucumber.steps.StepDefinition" }
)

public class SampleCucumberJUnitRunner {
  //Note: As with all Cucumber tests, the .feature file(s) will define what 
will actually run.
}

Unable to understand the source of error even though I have imported the class correctly. Am I missing something???

Any help would be appreciable. Thanks in advance!!

1
  • Getting this error - Type mismatch: cannot convert from Class<Cucumber> to Class<? extends Runner> Below is my code - package StepDefinitions; import org.junit.runner.RunWith; import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; @RunWith(Cucumber.class) @CucumberOptions(features = "src/test/resources/Features", glue = {"StepDefinitions"}) public class TestRunner { } @Someone can help me in this error?
    – user57773
    Dec 28, 2023 at 16:56

1 Answer 1

1

Change @RunWith(StepDefinition.class) to @RunWith(Cucumber.class).

The Cucumber runner needs to run with a class that extends Runner.class; StepDefinition.class does not extends Runner.class.

1
  • Does this answer your question, or do you need something else?
    – Marit
    Feb 4, 2018 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.