Installing and configuring Cucumber in Eclipse and IntelliJ IDEA involves setting up a Java + Maven or Gradle project, adding Cucumber dependencies, and configuring the environment to recognize .feature files and step definitions. Below is a detailed guide for both IDEs.
For Eclipse IDE:
Step 1: Install Eclipse IDE
Download from: https://www.eclipse.org/downloads/
Recommended: Eclipse IDE for Java Developers
Install Java JDK (Java 8 or higher): https://www.oracle.com/java/technologies/javase-downloads.html
Step 2: Install Cucumber Eclipse Plugin (Optional)
This plugin enables syntax highlighting and snippets for
.featurefiles.
Open Eclipse →
Help→Eclipse MarketplaceSearch for: Cucumber Eclipse Plugin
Click Install, then Restart Eclipse
Step 3: Create Maven Project
File→New→Maven Project
- Choose template: maven-archetype-quickstart
- Set
GroupId,ArtifactId, and click Finish
pom.xml<dependencies> <!-- Cucumber Core --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>7.14.0</version> </dependency> <!-- Cucumber JUnit --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-junit</artifactId> <version>7.14.0</version> <scope>test</scope> </dependency> <!-- JUnit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency> </dependencies>
Step 5: Create Folder Structure
Feature: Login Functionality Scenario: Successful login with valid credentials Given User is on Login page When User enters valid username and password Then User should be redirected to homepage
LoginSteps.java)package stepDefinitions; import io.cucumber.java.en.*; public class LoginSteps { @Given("User is on Login page") public void user_on_login_page() { System.out.println("User is on Login page"); } @When("User enters valid username and password") public void user_enters_credentials() { System.out.println("Entered valid credentials"); } @Then("User should be redirected to homepage") public void user_redirected_homepage() { System.out.println("Redirected to homepage"); } }
TestRunner.java)package runners; import org.junit.runner.RunWith; import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; @RunWith(Cucumber.class) @CucumberOptions( features = "src/test/resources/features", glue = "stepDefinitions" ) public class TestRunner { }
Step 7: Run Test
Right-click on
TestRunner.java→Run As→JUnit Test
For IntelliJ IDEA:
Download from: https://www.jetbrains.com/idea/download/
Step 2: Install Cucumber Plugin
Open IntelliJ →
Settings→PluginsSearch: Cucumber for Java
Click Install and restart
Step 3: Create a Maven Project
File→New→Project
- Choose
Maven
- Set name and location, click Finish
pom.xml as mentioned above
Step 5: Create Folder Structure & Add Files
Same as explained above. IntelliJ will automatically recognize resources and .feature files if placed correctly.
You can use IntelliJ features like:
Alt+Enter on undefined steps → to auto-create step definitions.
Right-click on .feature file → Run to execute.
Important Points for both IDEs:Glue in @CucumberOptions must point to the package containing step definitions.
.feature files must be UTF-8 encoded.
You can also use Cucumber with TestNG, just add relevant dependencies and use AbstractTestNGCucumberTests.
No comments:
Post a Comment