What are Feature Files?
Feature files are the heart of Cucumber-based test automation. They describe the behavior of your application in plain language using Gherkin syntax. In this framework, we use Spanish Gherkin (#language:es) to write our test scenarios.
Feature files are stored in:
Basic Structure
Every feature file follows this structure:Real Example: GeneracionReporte.feature
Here’s the actual feature file from our framework:This feature file is located at:
src/test/resources/features/GeneracionReporte.featureGherkin Keywords in Spanish
Característica (Feature)
Defines what feature or functionality is being tested:Escenario (Scenario)
Describes a single test case with specific steps:Esquema del escenario (Scenario Outline)
Defines a parameterized test template that runs multiple times with different data:Step Keywords
| Spanish | English | Purpose |
|---|---|---|
| Dado | Given | Sets up the initial context or preconditions |
| Cuando | When | Describes the action being performed |
| Entonces | Then | Verifies the expected outcome |
| Y | And | Continues the previous step type |
| Pero | But | Adds a contrasting step |
Examples of Each Step Type
Dado (Given) - Setup:Tags
Tags allow you to organize and filter tests. They start with@:
@test- Standard test cases@smoke- Quick smoke tests@regression- Regression test suite@wip- Work in progress@skip- Skip this scenario
Parameter Syntax
Parameters in Gherkin are enclosed in quotes and angle brackets:String Parameters
Use quotes"text" for static values:
Placeholder Parameters
Use angle brackets"<placeholder>" in Scenario Outlines:
File Organization
Organize your feature files logically:Best Practices for Feature Files
Best Practices for Feature Files
- One feature per file: Keep each feature file focused on a single functionality
- Descriptive names: Use clear, descriptive names like
GeneracionReporte.feature - Meaningful scenarios: Write scenario names that describe the business value
- Reusable steps: Write steps that can be reused across different scenarios
- Consistent formatting: Maintain consistent indentation (2 spaces is standard)
- Business language: Write in terms your stakeholders understand
- Avoid technical details: Keep feature files focused on behavior, not implementation
Ejemplos (Examples) Table
The Examples table provides test data for Scenario Outlines:Column names in the Examples table must exactly match the placeholder names used in the scenario steps.
Next Steps
Now that you understand feature files, learn how to implement the step definitions that bring these scenarios to life:- Step Definitions - Implement the Java code
- Data-Driven Tests - Master Scenario Outlines
- Test Examples - See complete examples