VOOZH about

URL: https://deepwiki.com/Accenture/Ocaramba/3.4-bdd-with-specflow-(ocaramba.tests.features)

⇱ BDD with SpecFlow (Ocaramba.Tests.Features) | Accenture/Ocaramba | DeepWiki


Loading...
Last indexed: 6 June 2026 (fb3580)
Menu

BDD with SpecFlow (Ocaramba.Tests.Features)

This page describes the Behavior-Driven Development (BDD) integration within the Ocaramba framework using SpecFlow. The Ocaramba.Tests.Features project provides a structured approach to writing human-readable tests in Gherkin syntax while leveraging Ocaramba's core driver management and Page Object Model (POM) capabilities.

Purpose and Scope

The Ocaramba.Tests.Features project serves as the primary BDD implementation layer. It integrates SpecFlow with NUnit to execute scenarios defined in .feature files. The project demonstrates how to:

  • Define test scenarios using Gherkin syntax.
  • Map Gherkin steps to C# code using Step Definitions.
  • Manage the WebDriver lifecycle via a specialized ProjectTestBase.
  • Share data and context between steps using SpecFlow's ScenarioContext.
  • Utilize dependency injection to provide DriverContext to step classes.

Project Structure and Setup

The project is organized into three main areas: Feature files, Step Definitions, and the Base Configuration. The project targets net8.0 Ocaramba.Tests.Features/Ocaramba.Tests.Features.csproj4-5 and relies on SpecFlow.NUnit for test execution Ocaramba.Tests.Features/Ocaramba.Tests.Features.csproj27 It uses BoDi for dependency injection Ocaramba.Tests.Features/Ocaramba.Tests.Features.csproj10

Implementation Overview Diagram

The following diagram illustrates the relationship between Gherkin files, the generated code-behind, and the Ocaramba framework entities.

Gherkin to Code Mapping


Sources: Ocaramba.Tests.Features/TestFeatures/SmokeTests.feature24-32 Ocaramba.Tests.Features/ProjectTestBase.cs39-43 Ocaramba.Tests.Features/StepDefinition/CommonSteps.cs33-48

ProjectTestBase and Lifecycle Management

The ProjectTestBase class in this project differs from other test runner implementations as it uses SpecFlow's [Binding] attribute and lifecycle hooks to manage the DriverContext.

Sources: Ocaramba.Tests.Features/ProjectTestBase.cs39-143

Step Definitions and Dependency Injection

Step definitions are contained in the StepDefinitions namespace. The CommonSteps class demonstrates how to interact with Page Objects using the shared DriverContext.

Data Flow: DriverContext Injection

Ocaramba uses the SpecFlow ScenarioContext to pass the DriverContext from the base hooks to the step classes.


Sources: Ocaramba.Tests.Features/ProjectTestBase.cs110-111 Ocaramba.Tests.Features/StepDefinition/CommonSteps.cs39-48

Key Functions in CommonSteps

Sources: Ocaramba.Tests.Features/StepDefinition/CommonSteps.cs33-143

Feature Files (Gherkin)

The project includes SmokeTests.feature, which covers common UI interactions such as dropdown selection and keyboard input.

FeatureScenarioSteps
SmokeTestsVerify default option selectedGiven, When, And, And, Then Ocaramba.Tests.Features/TestFeatures/SmokeTests.feature27-32
SmokeTestsKey Presses TestScenario Outline using <key> and <message> Ocaramba.Tests.Features/TestFeatures/SmokeTests.feature79-100

Sources: Ocaramba.Tests.Features/TestFeatures/SmokeTests.feature27-100

SmokeTests.feature.cs

This is a partial class generated by SpecFlow that maps Gherkin scenarios to NUnit test methods. It includes [TestFixture] Ocaramba.Tests.Features/TestFeatures/SmokeTests.feature.cs22 [Test] Ocaramba.Tests.Features/TestFeatures/SmokeTests.feature.cs76 and [Category] Ocaramba.Tests.Features/TestFeatures/SmokeTests.feature.cs78 attributes, allowing these BDD scenarios to be discovered by standard NUnit runners. It handles the execution lifecycle by calling testRunner.OnScenarioStart() Ocaramba.Tests.Features/TestFeatures/SmokeTests.feature.cs68 and testRunner.CollectScenarioErrors() Ocaramba.Tests.Features/TestFeatures/SmokeTests.feature.cs73

Configuration

The project is configured via standard Ocaramba configuration files and SpecFlow-specific settings:

Adding New Features

To extend the BDD suite:

  1. Create Feature File: Add a .feature file in the TestFeatures folder. Ensure the generator is configured in the .csproj Ocaramba.Tests.Features/Ocaramba.Tests.Features.csproj51-55
  2. Define Steps: Write scenarios using Gherkin syntax (e.g., Given, When, Then).
  3. Implement Steps:
  4. Use Page Objects: Instantiate Page Objects from the Ocaramba.Tests.PageObjects project within the step methods to perform actions Ocaramba.Tests.Features/StepDefinition/CommonSteps.cs53

Sources: Ocaramba.Tests.Features/StepDefinition/CommonSteps.cs23-33 Ocaramba.Tests.Features/ProjectTestBase.cs38-40 Ocaramba.Tests.Features/Ocaramba.Tests.Features.csproj51-55