Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpecFlow BDD Framework

BDD Tests License: MIT .NET SpecFlow

BDD test automation framework using SpecFlow (Gherkin) + Selenium WebDriver on .NET 8. Page Object Model, scenario outlines, living documentation, and CI/CD integration.


Scenarios

Feature Scenarios Tags
Login 6 (incl. Scenario Outline with 2 examples) @smoke, @regression
Inventory 3 @smoke, @regression
Checkout 3 @regression
Total 12

Quick Start

git clone https://github.com/mustafaautomation/specflow-bdd-framework.git
cd specflow-bdd-framework

dotnet restore
dotnet build
dotnet test

# Run smoke scenarios only
dotnet test --filter "Category=smoke"

# Generate living documentation
dotnet tool install --global SpecFlow.Plus.LivingDoc.CLI
livingdoc test-assembly bin/Debug/net8.0/SpecFlowBDD.dll -t bin/Debug/net8.0/TestExecution.json

Feature File Example

@login
Feature: Login

    Background:
        Given I am on the login page

    @smoke
    Scenario: Successful login with standard user
        When I login with "standard_user" and "secret_sauce"
        Then I should be on the inventory page

    @regression
    Scenario Outline: Login fails with invalid credentials
        When I login with "<username>" and "<password>"
        Then I should see the error "do not match"

        Examples:
            | username  | password |
            | bad_user  | bad_pass |
            | invalid   | wrong    |

Architecture

┌───────────────────���─────────────────────┐
│        Feature Files (Gherkin)           │
│  Login.feature │ Inventory │ Checkout    │
├─────────────────────────────────────────┤
│        Step Definitions                  │
│  LoginSteps │ InventorySteps │ ...       │
├─────────────────────────────────────────┤
│        Page Objects                      │
│  LoginPage │ InventoryPage │ CartPage    │
│  CheckoutPage                            │
├─────────────────────────────────────────┤
│        Hooks + Support                   │
│  WebDriverHooks │ DriverManager │ Config │
├─────────────────────────────────────────┤
│  SpecFlow │ Selenium │ NUnit │ FluentAs  │
└─────────────────────────────────────────┘

Key Patterns

ScenarioContext Dependency Injection

SpecFlow injects ScenarioContext into steps and hooks. WebDriver is shared via context:

[BeforeScenario]
public void BeforeScenario()
{
    var driver = DriverManager.CreateDriver();
    _scenarioContext.Set(driver, "WebDriver");
}

Step Definitions with Regex Bindings

[When(@"I login with ""(.*)"" and ""(.*)""")]
public void WhenILoginWith(string username, string password)
{
    _loginPage.Login(username, password);
}

Living Documentation

SpecFlow.Plus.LivingDoc generates browsable HTML from feature files + test results.


Project Structure

specflow-bdd-framework/
├── Features/
│   ├── Login.feature          # 6 scenarios (incl. outline)
│   ├── Inventory.feature      # 3 scenarios
│   └── Checkout.feature       # 3 scenarios
├── StepDefinitions/
│   ├── LoginSteps.cs
│   ├── InventorySteps.cs
│   └── CheckoutSteps.cs
├── Pages/
│   ├── LoginPage.cs
│   ├── InventoryPage.cs
│   ├── CartPage.cs
│   └── CheckoutPage.cs
├── Hooks/
│   └── WebDriverHooks.cs      # Before/After scenario driver lifecycle
├── Support/
│   ├── TestConfig.cs           # Env-based config
│   └── DriverManager.cs        # Chrome WebDriver factory
├── SpecFlowBDD.csproj
└── .github/workflows/bdd-tests.yml

Stack

Tool Purpose
SpecFlow 3.9 BDD framework with Gherkin parser
Selenium 4.27 Browser automation
NUnit 4.3 Test runner
FluentAssertions 7.0 Readable assertions
WebDriverManager Automatic ChromeDriver setup
.NET 8 Runtime
LivingDoc Generated documentation from features

License

MIT


Built by Quvantic

About

SpecFlow BDD + Selenium .NET 8 framework with Gherkin features and living documentation

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages