基于Selenium+TestNG+Maven+Jenkins框架,Cucumber所需Maven依赖有哪些?
Hey there! Let's walk through exactly what Maven dependencies you need to integrate Cucumber with your TestNG-based automation framework, plus some key setup details to tie everything together.
Required Maven Dependencies
Add these to your pom.xml file. I’ve used recent stable versions (7.14.0) below—just make sure all Cucumber dependencies share the same version to avoid compatibility headaches:
<!-- Core Cucumber functionality --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-core</artifactId> <version>7.14.0</version> <scope>test</scope> </dependency> <!-- Bridge between Cucumber and TestNG (critical for running scenarios as TestNG tests) --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-testng</artifactId> <version>7.14.0</version> <scope>test</scope> </dependency> <!-- For writing step definitions in Java (works seamlessly with your existing Selenium code) --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>7.14.0</version> <scope>test</scope> </dependency> <!-- Optional: For generating human-readable HTML reports --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-html-reporter</artifactId> <version>7.14.0</version> <scope>test</scope> </dependency>
Key Setup Tips
- Version Compatibility: Ensure your existing TestNG version is 7.0 or newer (Cucumber 7.x+ requires this). Double-check that no conflicting versions are pulled in via Maven—use
mvn dependency:treeto verify if needed. - TestNG Runner Class: You’ll need a runner class to trigger Cucumber scenarios through TestNG. Here’s a minimal example:
import io.cucumber.testng.AbstractTestNGCucumberTests; import io.cucumber.testng.CucumberOptions; @CucumberOptions( features = "src/test/resources/features", // Path to your .feature files glue = "com.yourteam.stepdefinitions", // Package containing your step definitions plugin = {"pretty", "html:target/cucumber-reports.html"} // Report formats ) public class CucumberTestRunner extends AbstractTestNGCucumberTests { } - Selenium Integration: Since you already have Selenium set up, you can directly use your page objects, drivers, and utility classes inside your Cucumber step definitions—no extra dependencies required here.
- Jenkins Integration: Use the standard
mvn testcommand in your Jenkins job to run the tests. For better visibility, install the Jenkins Cucumber Reports plugin to display detailed scenario results directly in the Jenkins dashboard.
内容的提问来源于stack exchange,提问作者Madhavan
相关产品推荐
相关产品推荐

