Foodband

Enable Cucumber support

To be able to use Cucumber in your application, make sure that the necessary plugins are enabled and add the Cucumber library to your project.

Enable plugins

In IntelliJ Ultimate , the required plugins are bundled and enabled by default. However, we recommend you to make sure that they are switched on.

In IntelliJ Community , the necessary plugins are not bundled, that is why you need to install and enable them.

In the Settings/Preferences dialog Ctrl+Alt+S , select Plugins .

Switch to the Installed tab and make sure that the following plugins are enabled (the plugins must be enabled in the specified order):

Cucumber for Java

Cucumber for Groovy (optional: install this plugin if you want to create step definitions in Groovy)

If the plugins are not installed, switch to the Marketplace tab, type their names in the search field in the specified order, and click Install next to each of them.

Apply the changes and close the dialog. Restart the IDE if prompted.

Add the Cucumber library

Follow these steps to add a library if you're building your project with the native IntelliJ IDEA builder:

From the main menu, select File | Project Structure ( Ctrl+Alt+Shift+S ) or click on the toolbar.

Under Project Settings , select Libraries and click | From Maven .

In the dialog that opens, specify the artifact of the library version that you want to use in your project, for example: io.cucumber:cucumber-java:jar:6.1.1 or io.cucumber:cucumber-java8:jar:6.1.1 (if you want to use lambda expressions in step definitions).

Apply the changes and close the Project Structure dialog.

Follow these steps if you're using Maven in your project:

In your pom.xml , add the following dependencies (make sure to specify the latest version of Cucumber):

Alternatively, if you want to use lambda expressions in step definitions, add:

Press Ctrl+Shift+O or click in the Maven tool window to import the changes.

For more information on how to work with Maven, refer to Maven dependencies.

Use these steps if you're building your project with Gradle.

Open your build.gradle and add the following dependencies (make sure to specify the latest version of Cucumber):

For Gradle 5 and later, add:

Alternatively, if you want to use lambda expressions in step definitions, add:

For Gradle 4.10.3 and earlier, add:

Alternatively, if you want to use lambda expressions in step definitions, add:

To find out your Gradle version, run ./gradlew —version in the Terminal ( Alt+F12 ).

When the dependencies are added to your build.gradle , press Ctrl+Shift+O or click in the Gradle tool window to import the changes.

Apart from the Cucumber library, you might need to add a library for JUnit or another testing framework.

Prepare folder structure

Make sure that your project has the following folders:

Test Sources Root: a folder that stores your test code

Test Resources Root: a folder that stores files associated with your test sources

add cucumber plugin into intellij idea

I want to add add cucumber plugin into intellij idea .I have did this using eclips.

2 Answers 2

In IntelliJ, go to file -> settings -> plugins -> choose the plugin Cucumber for Java

Normally you should be able to use all annotations and IntelliJ will recognize the file-extensions

You need to add from IDE go to settings —>plugins then search cucumber-java click ok and you need to restart IDE

Not the answer you're looking for? Browse other questions tagged java selenium maven cucumber testng or ask your own question.

Related
Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.11.26.40833

By clicking "Accept all cookies", you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

10 Minute Tutorial

We'll use Cucumber to develop a small library that can figure out whether it's Friday yet.

Please be aware that this tutorial assumes that you have a:

  • Basic understanding of the Java programming language
  • Basic understanding of the Gradle file
  • Basic understanding of the Kotlin programming language
  • Basic understanding of the Gradle file
  • Basic understanding of the Javascript programming language
  • Basic understanding of the Ruby programming language
  • Basic understanding of the Bundler tool and Gemfile
  • Some experience using a terminal
  • Some experience using a text editor

Before we begin, you will need the following:

    — version 3.3.1 or higher
    (Java 9 and higher are not yet supported by Cucumber) — version 3.3.1 or higher (which will be used in this tutorial)

Open a terminal to verify that Node.js is installed properly:

Both of these commands should print a version number.

Open a terminal to verify that Ruby is installed properly:

Both of these commands should print a version number.

Create an empty Cucumber project

Decide whether you'd prefer to use Gradle or Maven.

With Maven

For Maven, we'll start by creating a new project directory with the cucumber-archetype Maven plugin. Open a terminal, go to the directory where you want to create your project, and run the following command:

You should get something like the following result:

Change into the directory that was just created by running the following command:

Open the project in IntelliJ IDEA:

  • File -> Open… -> (Select the pom.xml)
  • Select Open as Project

With Gradle

One way to create this sample Cucumber project using Gradle is to convert the above generated Maven archetype into a Gradle project.

Run the following command from the hellocucumber directory:

Add following dependency configuration to your build.gradle file:

Add the following Task to your build.gradle file:

Foodband

Note that you also need to add the necessary dependencies/configurations to build.gradle depending on which version of Gradle you are using. See the Build Tools section. If you follow this guide be sure to set your —glue path to hellocucumber for this tutorial.

If you have not already, open the project in IntelliJ IDEA:

  • File -> Open… -> (Select build.gradle)
  • Select Open as Project

Decide whether you'd prefer to use Gradle or Maven.

With Maven

For Maven, we'll start by creating a new project directory with the cucumber-archetype Maven plugin. Open a terminal, go to the directory where you want to create your project, and run the following command:

You should get something like the following result:

Change into the directory that was just created by running the following command:

Open the project in IntelliJ IDEA:

  • File -> Open… -> (Select the pom.xml)
  • Select Open as Project

With Gradle

One way to create this sample Cucumber project using Gradle is to convert the above generated Maven archetype into a Gradle project.

Run the following command from the hellocucumber directory:

Add following dependency configuration to your build.gradle file:

Add the following Task to your build.gradle file:

Note that you also need to add the necessary dependencies/configurations to build.gradle depending on which version of Gradle you are using. See the Build Tools section. If you follow this guide be sure to set your —glue path to hellocucumber for this tutorial.

If you have not already, open the project in IntelliJ IDEA:

  • File -> Open… -> (Select build.gradle)
  • Select Open as Project

To use Kotlin, we need to add it to our project:

  • Add a directory named kotlin in your src/test directory and mark it as Test Sources Root . In IntelliJ, you can do so by right-clicking on the kotlin directory and selecting "Mark Directory as" > "Test Sources Root".
  • Create the hellocucumber package inside the kotlin directory.
  • Create a Kotlin class called RunCucumberTest inside the hellocucumber package. IntelliJ might tell you that Kotlin is not configured; click "Configure". Your pom.xml should now look like this:
  • Copy the annotations from the RunCucumberTest.java class to the RunCucumberTest.kt class. If you are using IntelliJ, it will offer to translate the Java code to Kotlin code. Otherwise you'll have to write your own.

Your RunCucumberTest.kt class should now look like this:

  • Now you can delete the RunCucumberTest.java class.
  • Create a Kotlin class called StepDefs inside the hellocucumber package.
  • Copy the import statements from StepDefinitions.java to StepDefs.kt ; you'll need them later.
  • Finally, delete the StepDefinitions.java class (or even the java directory).

To use Kotlin in our project, we need to take some extra steps:

  • Add a directory named kotlin in your src/test directory and mark it as Test Sources Root . In IntelliJ, you can do so by right-clicking on the kotlin directory and selecting "Mark Directory as" > "Test Sources Root".
  • Create the hellocucumber package inside the kotlin directory.
  • Create a Kotlin class called RunCucumberTest inside the hellocucumber package and copy the annotations from the RunCucumberTest.java class to the RunCucumberTest.kt class. If you are using IntelliJ, it will offer to translate the Java code to Kotlin code. Otherwise you'll have to write your own.

Your RunCucumberTest.kt class should now look like this:

We'll start by creating a new directory and an empty Node.js project.

Add Cucumber as a development dependency:

Open package.json in a text editor and change the test section so it looks like this:

Prepare the file structure:

Create a file called cucumber.js at the root of your project and add the following content:

Also, create a file called features/step_definitions/stepdefs.js with the following content:

We'll start by creating a new directory and an empty Ruby project.

Create a Gemfile with the following content:

Install Cucumber and prepare the file structure:

You now have a small project with Cucumber installed.

Verify Cucumber installation

To make sure everything works together correctly, let's run Cucumber.

Maven:

Gradle:

Maven:

Gradle:

You should see something like the following:

Cucumber's output is telling us that it didn't find anything to run.

Write a Scenario

When we do Behaviour-Driven Development with Cucumber we use concrete examples to specify what we want the software to do. Scenarios are written before production code. They start their life as an executable specification. As the production code emerges, scenarios take on a role as living documentation and automated tests.

Try running an Example Mapping workshop in your team to design examples together.

In Cucumber, an example is called a scenario. Scenarios are defined in .feature files, which are stored in the src/test/resources/hellocucumber features features directory (or a subdirectory).

One concrete example would be that Sunday isn't Friday.

Create an empty file called src/test/resources/hellocucumber/is_it_friday_yet.feature src/test/resources/hellocucumber/is_it_friday_yet.feature features/is_it_friday_yet.feature features/is_it_friday_yet.feature with the following content:

The first line of this file starts with the keyword Feature: followed by a name. It's a good idea to use a name similar to the file name.

The second line is a brief description of the feature. Cucumber does not execute this line because it's documentation.

The fourth line, Scenario: Sunday is not Friday is a scenario, which is a concrete example illustrating how the software should behave.

The last three lines starting with Given , When and Then are the steps of our scenario. This is what Cucumber will execute.

See scenario reported as undefined

Now that we have a scenario, we can ask Cucumber to execute it.

Maven:

Gradle:

Maven:

Gradle:

Cucumber is telling us we have one undefined scenario and three undefined steps. It's also suggesting some snippets of code that we can use to define these steps:

Copy each of the three snippets for the undefined steps and paste them into src/test/java/hellocucumber/StepDefinitions.java src/test/kotlin/hellocucumber/Stepdefs.kt features/step_definitions/stepdefs.js features/step_definitions/stepdefs.rb .

Unfortunately, Cucumber does not generate snippets in Kotlin. But fortunately IntelliJ can convert the Java code to Kotlin code for you. You might need to improve the translated code, to make it more idiomatic. You might also need to add the following import statements (if you hadn't already).

Your StepDefs.kt file should now look like this:

See scenario reported as pending

Run Cucumber again. This time the output is a little different:

Cucumber found our step definitions and executed them. They are currently marked as pending, which means we need to make them do something useful.

See scenario reported as failing

The next step is to do what the comments in the step definitions is telling us to do:

Write code here that turns the phrase above into concrete actions

Try to use the same words in the code as in the steps.

If the words in your steps originated from conversations during an Example Mapping session, you're building a Ubiquitous Language, which we believe is a great way to make your production code and tests more understandable and easier to maintain.

Foodband