BDD test automation framework using SpecFlow (Gherkin) + Selenium WebDriver on .NET 8. Page Object Model, scenario outlines, living documentation, and CI/CD integration.
| Feature | Scenarios | Tags |
|---|---|---|
| Login | 6 (incl. Scenario Outline with 2 examples) | @smoke, @regression |
| Inventory | 3 | @smoke, @regression |
| Checkout | 3 | @regression |
| Total | 12 |
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@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 |┌───────────────────���─────────────────────┐
│ 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 │
└─────────────────────────────────────────┘
SpecFlow injects ScenarioContext into steps and hooks. WebDriver is shared via context:
[BeforeScenario]
public void BeforeScenario()
{
var driver = DriverManager.CreateDriver();
_scenarioContext.Set(driver, "WebDriver");
}[When(@"I login with ""(.*)"" and ""(.*)""")]
public void WhenILoginWith(string username, string password)
{
_loginPage.Login(username, password);
}SpecFlow.Plus.LivingDoc generates browsable HTML from feature files + test results.
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
| 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 |
MIT
Built by Quvantic