How to Fix My Cucumber Expectation Error When Polling

Getting Error for @CucumberOptions and seems cucumber.class deprecated

If you look at the source code for io.cucumber.junit.platform.engine.Cucumber you'll see that:

https://github.com/cucumber/cucumber-jvm/blob/main/junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Cucumber.java

package io.cucumber.junit.platform.engine;

import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
import org.junit.platform.commons.annotation.Testable;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Test discovery annotation. Marks the package of the annotated class for test
* discovery.
* <p>
* Maven and Gradle do not support the
* {@link org.junit.platform.engine.discovery.DiscoverySelectors} used by
* Cucumber. As a workaround Cucumber will scan the package of the annotated
* class for feature files and execute them.
* <p>
* Note about Testable: While this class is annotated with @Testable the
* recommended way for IDEs and other tooling use the selectors implemented by
* Cucumber to discover feature files.
* <p>
*
* @deprecated Please use the JUnit Platform Suite to run Cucumber in
* combination with Surefire or Gradle. E.g: <code><pre>{@code
*package com.example;
*
*import org.junit.platform.suite.api.ConfigurationParameter;
*import org.junit.platform.suite.api.SelectClasspathResource;
*import org.junit.platform.suite.api.Suite;
*
*import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
*
*@Suite
*@SelectClasspathResource("com/example")
*@ConfigurationParameter(
* key = GLUE_PROPERTY_NAME,
* value = "com.example"
*)
*public class RunCucumberTest {
*}
*}</pre></code>
* @see CucumberTestEngine
*/
@API(status = Status.DEPRECATED)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Testable
@Deprecated
public @interface Cucumber {

}

If you are using Maven you can download the sources with mvn dependency:sources. Though typically you won't have to as your IDE can do this for you.

Now there are a few things to observe here:

  1. If you search for the JUnit Platform you'll find that it is part of JUnit 5. However @RunWith is part of JUnit 4.

    This means that you are mixing different framework versions together. You can not expect that to work.

  2. There is a code snippet in the Javadoc that suggests the correct way to use Cucumber with JUnit 5.

package com.example;

import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("com/example")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example")
public class RunCucumberTest {
}

You should consider using that.

Each open source project is different but it's also good to look at the source. Documentation may be included:

https://github.com/cucumber/cucumber-jvm/tree/main/junit-platform-engine

And since this is a JUnit 5 engine, the JUnit 5 documentation is good to read too.

https://junit.org/junit5/docs/current/user-guide/

@Before doesn't execute in java Cucumber Step

  1. Make sure you are using cucumber.annotation.Before rather than org.junit.Before. Cucumber will not process JUnit annotations. (More information in the Scenario Hooks section of this blog post.)

  2. Make sure your @Before method is public, not private.

How to resolve runtime.cucumberexception for error parsing feature file

When using a Scenario Outline, you need to provide an "Examples" section. In this case, it looks like you don't need a scenario outline at all, so:

Feature: Search India on BBC website and verify search.

@Search
Scenario: Search India on BBC website and verify it.
Given I open the firefox browser
And I navigating to BBc website
Then I click at search textbox
And I enter "India" in search textbox
And I click at Search button
Then I should be taken to search page
And I verify India on search page

If you do need a scenario outline, you want something like:

Feature: Search India on BBC website and verify search.

@Search
Scenario Outline: Search India on BBC website and verify it.
Given I open the firefox browser
And I navigating to BBc website
Then I click at search textbox
And I enter "<country>" in search textbox
And I click at Search button
Then I should be taken to search page
And I verify <country> on search page

Examples:
| country |
| India |
| China |


Related Topics



Leave a reply



Submit