This repository contains UI automation tests for the Baasic Demo Site using SpecFlow, Selenium WebDriver, and NUnit on .NET 8.
SpecFlowPhotoGallery.Specs/
├── Drivers/
│ └── WebDriverContext.cs # WebDriver setup and teardown
├── Features/
│ └── Register.feature # Gherkin feature file(s)
├── Pages/
│ ├── HomePage.cs # Page Object for Home page
│ └── RegisterPage.cs # Page Object for Register page
├── StepDefinitions/
│ ├── RegisterActionSteps.cs # Step definitions for actions
│ └── RegisterAssertionSteps.cs # Step definitions for assertions
├── Hooks.cs # SpecFlow hooks for scenario setup/teardown
├── SpecFlowPhotoGallery.Specs.csproj
└── ...
- .NET 8 SDK
- Chrome browser (latest version recommended)
- ChromeDriver is managed automatically via NuGet
-
Restore dependencies:
dotnet restore
-
Build the project:
dotnet build
-
Run the tests:
dotnet test
This will launch Chrome, maximize the window, and execute the SpecFlow scenarios.
-
Open the solution in Visual Studio
-
Restore NuGet packages (right-click on the solution in Solution Explorer > Restore NuGet Packages)
-
Build the solution (
Ctrl + Shift + B) -
Open the Test Explorer (Test > Windows > Test Explorer) and select the test you want to run and click on "Run" button
- The tests use SpecFlow with NUnit and Selenium WebDriver.
- The browser window is maximized automatically at the start of the scenario.
- All WebDriver setup and disposal is handled in
WebDriverContextandHooks.cs. - Feature files are located in the
Features/directory and step definitions inStepDefinitions/. - Page Objects are in the
Pages/directory.
- Ensure your Chrome browser is up to date to match the ChromeDriver version.
- If you encounter issues with element selectors, check the HTML structure and update the Page Object selectors accordingly.
- For headless execution, you can modify
WebDriverContextto add ChromeOptions with headless mode.
- Run your tests:
dotnet testThis will generate a test execution JSON file (usually in the TestResults folder).
- Install the LivingDoc CLI tool (if not already installed):
dotnet tool install --global SpecFlow.Plus.LivingDoc.CLIOr update it:
dotnet tool update --global SpecFlow.Plus.LivingDoc.CLI- Generate the HTML report:
livingdoc test-assembly bin\Debug\net8.0\SpecFlowPhotoGallery.Specs.dll -t bin\Debug\net8.0\TestExecution.json -o LivingDoc.htmlThis will create a LivingDoc.html file in your current directory.
- LivingDoc is a rich HTML report for SpecFlow projects.
- It shows feature files, scenarios, step results, and execution details in a user-friendly format.
- You must run your tests first so that the execution data is available.
- The generated
LivingDoc.htmlcan be opened in any browser and shared with your team. - For more options, see the SpecFlow LivingDoc documentation.
This project uses SpecFlow with .NET 8 and generates LivingDoc documentation for your BDD scenarios.
-
Run the provided script:
- Use the
run-tests-with-livingdoc.batscript in the root directory to run your tests and automatically generate the LivingDoc HTML report. - The script will:
- Run all tests in the
SpecFlowPhotoGallery.Specsproject. - Generate
TestExecution.json(required for LivingDoc). - Create/update
LivingDoc.htmlin theSpecFlowPhotoGallery.Specsdirectory.
- Run all tests in the
Usage:
run-tests-with-livingdoc.bat
- Use the
-
View the documentation:
- Open
SpecFlowPhotoGallery.Specs\LivingDoc.htmlin your browser to see the latest LivingDoc report.
- Open
- .NET 8 SDK
- LivingDoc CLI installed globally:
dotnet tool install --global SpecFlow.Plus.LivingDoc.CLI
- Chrome browser (for Selenium tests)
- The LivingDoc will not be generated automatically by
dotnet testalone. Always use the provided script for full automation. - If you add or change features, simply re-run the script to update the documentation.
Feel free to contribute or open issues for improvements!