IntelliJ IDEA 2020.3 Help

Create step definitions

In Cucumber, step definitions should be stored in a named package under Test Sources Root. Keeping definitions in the default package might result in an error as IntelliJ IDEA will not be able to locate them.

Create a package for step definitions

  1. Right-click Test Sources Root icon Test Sources Root in the Project tool window and select New | Package.

  2. Give the package a meaningful name and press Enter .

    A package for step definitions in the Project tool window

Add step definitions

If a .feature file refers to a non-existent step, IntelliJ IDEA recognizes and highlights such a step, and provides an intention action that helps create the missing step definition.

  1. Place the caret at a step in your .feature file and press Alt+Enter .

    The list of suggested intention actions opens.

  2. Select Create step definition to create a definition only for one step, or select Create all step definitions to add definitions for all steps in a scenario.

    Creating steps definitions from the feature file

  3. If you already have definition files in your project, the IDE prompts you select to which file you want to add the new step definitions. You can select one of the existing files or create a new one.

  4. If you opt to create a new step definition file, a dialog opens. Name the new file, select the type (Java, Java 8, or Groovy) and specify its location.

    Note that files with step definitions should be located in a dedicated package. Keeping them in the default package might result in an error.

    Click OK.

    Creating a new file for step definitions
  5. In the selected step definition file that opens in the editor, enter the desired code.

Note the following:

  • To be able to create step definitions in Groovy, the Cucumber for Groovy plugin must be installed and enabled.

  • To be able to use lambda expressions in step definitions (Java 8), the corresponding library must be added to the project.

Last modified: 19 August 2020