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:
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.
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
Make sure you are using
cucumber.annotation.Before
rather thanorg.junit.Before
. Cucumber will not process JUnit annotations. (More information in the Scenario Hooks section of this blog post.)Make sure your @Before method is
public
, notprivate
.
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
How to Add "Access-Control-Allow-Origin" Headers to API Response in Ruby
Mongomapper Many to Many Issue with Array
Ruby Was-Sdk V2:Seahorse::Client::Networkingerror Exception: Ssl_Connect
Create and Initialize Instances of a Class with Sequential Names
Accessing Values Through Ajax Calls and Partials in Rails
Metasploit Induction of Bundle and Rake
Deleting a Line in a Text File
Ruby Selenium Web Drive: How to Find Specific Element by Xpath Div Id and CSS Class
Need Help on Join Table, Limiting Results to Only the Resource Id
Scope That Has Three Levels Deep Joins
Rexml::Document.New How to Give Encode Parameters on This Line
Require Self Made Gem in Jruby Fails After Update to Jruby-1.7.13
How to Properly Create a Associated Record Just After the Associator Record Creation
Multiple Limit Condition in Mongodb
How to Properly Install Bootsnap on Windows
Delete from Database with Specific Details in Ruby