When writing Steps in Cucumber, parameters are often used to make Step Definitions more flexible.
To facilitate step writing and improve parameter usage, a tool has been developed that provides built-in parameter completion suggestions.
Installation
-
Download the JAR file:
- Go to Bitbucket → https://bitbucket.org/nir_gallner/cucumberstepsuggest/
- go to the match branch. Depends on your IntelliJ version.
- Find the JAR file in
build/libs/cucumberstepsuggest-YOUR.VERSION.JARdirectory. - Download the JAR to your PC.
If you don’t find the match version, tha you can Change the IntelliJ version:
- Clone the project from Bitbucket here → https://bitbucket.org/nir_gallner/cucumberstepsuggest/
- Then, modify the IntelliJ version in the
build.gradle.ktsfile to match your IntelliJ version:
***
version = "YOUR.VERSION"
***
intellij {
version.set("YOUR.VERSION")
}
***
- Compile the code. You can find the JAR file in
build/libs/cucumberstepsuggest-YOUR.VERSION.JARdirectory.
-
Move the JAR file to a convenient location on your computer.
-
Installing the Plugin in IntelliJ
- Open IntelliJ IDEA.
- Navigate to File → Settings → Plugins.
- Click Install Plugin from Disk.
- Select the JAR file you saved on your computer.
- Click Apply, then OK.
- Restart IntelliJ for the changes to take effect.
Tool Implementation Requirements:
-
Create a new class named
CucumberParameterDefinitionsinside theco.verisoft.fw.cucumberpackage, where all parameter names will be defined. -
For each parameter:
- Define a name for the parameter, e.g.,
direction. - Add a function inside the
CucumberParameterDefinitionsclass to define the parameter, for example:
- Define a name for the parameter, e.g.,
package co.verisof.fw.cucumber;
import io.cucumber.java.ParameterType;
public class CucumberParameterDefinitions {
@ParameterType("UP|DOWN|RIGHT|LEFT")
public String direction(String string) {
return string;
}
}
- The function name represents the parameter name.
- The
@ParameterType()annotation above the function specifies the possible parameter values, separated by|. - The function receives a
Stringand returns the same value.
-
The parameter can then be used in a step like this:
@Then("user scrolls the screen to {direction} direction") public void userScrollsTheScreenToDirection(String directionString) { //scroll the screen to the specified direction }
How to Use the Tool:
When writing a scenario, if the user places the cursor on a parameter inside curly braces {} and presses CTRL + P, IntelliJ’s built-in suggestion popup will appear, allowing quick and easy selection of the desired parameter.
ℹ️ Info: Remember To Save your
CucumberParameterDefinitionsfile after updating it.
If not, the plugin won’t recognize the parameter name