Selenium-Cucumber Pro Extension
Professional Selenium Java step definition generator for Cucumber BDD testing

Features
Advanced Step Generation
- Smart Parameter Detection: Automatically detects quoted strings, numbers, and angle bracket parameters
- Professional Code Formatting: Clean, well-structured Java code with proper indentation
- Complete Method Templates: Includes try-catch blocks, documentation, and Selenium patterns
- Duplicate Prevention: Intelligent duplicate step detection and unique method naming
Multiple Generation Options
- Selection-based Generation: Generate from selected text or entire file
- Quick Actions Menu: Easy access to all features via status bar
- File Creation: Create new step definition files directly
- Clipboard Integration: Automatic copying to clipboard
Extensive Configuration
- Package & Class Names: Customizable package and class naming
- Framework Support: Cucumber, TestNG, and JUnit support
- Import Management: Custom import statements
- Code Style Options: Multiple formatting and naming conventions
🔧 Professional Features
- Error Handling: Comprehensive error handling and validation
- Context Menu Integration: Right-click options in feature files
- Keyboard Shortcuts: Quick access via customizable shortcuts
- Progress Indicators: Visual feedback during generation
📦 Installation
- Open VS Code
- Go to Extensions (
Ctrl+Shift+X)
- Search for "Selenium-Cucumber Pro"
- Click Install
🎮 Usage
Quick Start
- Open a Cucumber
.feature file
- Click the "🥒 Cucumber Steps" button in the status bar
- Select "Generate Step Definitions"
- Your step definitions are copied to clipboard!
Available Commands
| Command |
Shortcut |
Description |
| Generate Step Definitions |
Ctrl+Shift+G |
Generate from entire file or selection |
| Quick Actions |
Ctrl+Shift+Q |
Open quick actions menu |
| Generate from Selection |
Ctrl+Shift+S |
Generate only from selected text |
- Right-click in
.feature files for quick access
- Generate from selection when text is selected
- Explorer context menu for feature files
🔧 Configuration
Access settings via File > Preferences > Settings and search for "Cucumber":
Basic Settings
{
"cucumberStepGen.packageName": "com.example.stepdefinitions",
"cucumberStepGen.className": "StepDefinitions",
"cucumberStepGen.framework": "cucumber"
}
Advanced Settings
{
"cucumberStepGen.generateComments": true,
"cucumberStepGen.generateTryCatch": true,
"cucumberStepGen.methodNamingConvention": "camelCase",
"cucumberStepGen.autoDetectParameters": true,
"cucumberStepGen.outputFormat": "formatted"
}
Example Output
Feature: Login functionality
Scenario: Successful login
Given I am on the login page
When I enter username "testuser" and password "password123"
Then I should see the dashboard
Generated Output
package com.example.stepdefinitions;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import io.cucumber.java.en.Then;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.testng.Assert;
/**
* Cucumber Step Definitions
* Generated by Selenium-Cucumber Extension
*/
public class StepDefinitions {
private WebDriver driver;
/**
* Step: Given I am on the login page
*/
@Given("^I am on the login page$")
public void iAmOnTheLoginPage() {
try {
// TODO: Implement step logic for: I am on the login page
// Setup/precondition logic
// driver.get("URL");
} catch (Exception e) {
throw new RuntimeException("Failed to execute step", e);
}
}
/**
* Step: When I enter username "testuser" and password "password123"
* Parameters: 2
*/
@When("^I enter username \"(.*?)\" and password \"(.*?)\"$")
public void iEnterUsernameAndPassword(String param1, String param2) {
try {
// TODO: Implement step logic
// Available parameters:
// String param1
// String param2
// Action/interaction logic
// WebElement inputField = driver.findElement(By.id("inputId"));
// inputField.sendKeys("value");
} catch (Exception e) {
throw new RuntimeException("Failed to execute step", e);
}
}
}
Advanced Features
Parameter Detection
The extension automatically detects:
- Quoted strings:
"example" → "(.*?)"
- Numbers:
123 → (\\d+)
- Angle brackets:
<username> → (.*)
Code Templates
Smart templates based on step types:
- Given steps: Setup and precondition patterns
- When steps: Action and interaction patterns
- Then steps: Assertion and verification patterns
Helper Methods
Generated classes include utility methods:
private WebElement findElementWithWait(By locator) {
return wait.until(driver -> driver.findElement(locator));
}
private boolean isElementDisplayed(By locator) {
try {
return driver.findElement(locator).isDisplayed();
} catch (Exception e) {
return false;
}
}
Supported Step Patterns
The extension recognizes these Cucumber keywords:
Given - Setup/preconditions
When - Actions/interactions
Then - Assertions/verifications
And - Continuation steps
But - Negative conditions
Code Snippets
The extension includes helpful code snippets:
given - Generate Given step template
when - Generate When step template
then - Generate Then step template
cucumberClass - Full step definition class
pageObject - Page Object Model template
Troubleshooting
Common Issues
No steps generated?
- Ensure steps start with
Given, When, Then, or And
- Check that the file contains valid Cucumber syntax
Invalid method names?
- The extension automatically sanitizes method names
- Special characters are removed or converted
Configuration not working?
- Restart VS Code after changing settings
- Check settings format matches examples
Error Messages
| Message |
Solution |
| "No active editor found" |
Open a file in the editor |
| "No valid Cucumber steps found" |
Check step syntax (Given/When/Then) |
| "Package name must be valid" |
Use valid Java package format |
Contributing
We welcome contributions! Please see our Contributing Guide.
Development Setup
- Clone the repository
- Run
npm install
- Open in VS Code
- Press
F5 to launch extension development host
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Cucumber community for the amazing BDD framework
- Selenium team for web automation tools
- VS Code team for the excellent extension API
Support
Happy Testing! 🧪✨
Made with ❤️ by Gyana Prakash Khandual