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
Right-click Test Sources Root in the Project tool window and select .
Give the package a meaningful name and press Enter.
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.
Place the caret at a step in your .feature file and press Alt+Enter.
The list of suggested intention actions opens.
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.
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.
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.
Select Java 8 to use lambda expressions in step definitions or Java to use annotations.
Note that files with step definitions should be located in a dedicated package. Keeping them in the default package might result in an error.
In the selected step definition file that opens in the editor, enter the desired code.
Note the following:
Jump between steps and definitions
Make sure that the file with step definitions is located in a dedicated package. Otherwise, you won't be able to use navigation.
Jump to a step definition
In a .feature file, keep Control pressed and hover over a step. When it turns into a link, click it to jump to its definition.
Alternatively, place the caret at a step and selectfrom the main menu or just press Control+B.
Jump to a step from its definition
In a file with step definitions, keep Control pressed and hover over a step definition. When it turns into a link, click it to jump to the step.
Alternatively, place the caret at the necessary step definition and selectfrom the main menu or just press Control+B.