The Cucumber framework can be integrated with any Java-based test automation framework. In this tutorial, we’ll see how to use Selenium WebDriver with Cucumber for a simple test scenario
Required Libraries:
1. Cucumber (core, java, junit, picocontainer)
2. Selenium WebDriver
3. WebDriverManager
4. JUnit
5. Maven Surefire Plugin
Setting up the Project
1. Create a Java project in your IDE.
2. Use Maven as the build tool.
3. Find pom.xml and add the dependencies.
Example pom.xml
Selenium Cucumber BDD Project Structure
Browser Invocation in Hooks
Set up and close the browser in a Hooks class using Cucumber annotations:
@Before – launch browser
@After – close browser
This ensures each scenario starts and ends cleanly.
Use the Runner class for Execution:
The Runner file is placed in src/test/runners. We can specify the feature files to be executed, tags to filter scenarios, and HTML report configurations. Using the Maven Surefire plugin, the scripts can be executed through the command line.
Reporting
After execution, reports will be generated and stored inside the reports folder. These can be enhanced using plugins like pretty, html, or extent-reports.
GitHub Source Code: You can find a demo Selenium Cucumber BDD project in ths github report: https://github.com/qafeast/CucumberJavaSelenium/blob/main