The goal of this project is to provide a good starting point for those looking to use SpecFlow and Selenium together. It is also intended to demonstrate how to implement design patterns in a test framework, where many test frameworks will violate many different principles like SOLID, Static Cling (this one is always the most common), and Explicit Dependencies.
Resources
- Selenium
- SpecFlow
- FluentAssertions
- SOLID in Testing
- The Wrong Abstraction
- Basic Programming Principles
- Principles of Test Automation
- Software Testing Anti-patterns
- Overreliance on End to End Testing
- Cyclomatic and Cognitive Complexity
- .NET Framework
- Mac setup
- Build scripts (cake?)
- Windows setup
- .NET Standard
- Visual Studio guide
- Appium
- Docker Selenium Grid execution
Download and install Visual Studio or JetBrains Rider
The required .net frameworks should download/install with your IDE of choice.
No extra setup necessary
Visual Studio needs a little extra configuration. Install these extensions;
- xUnit.NET 2
- SpecFlow
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
After installation:
$ brew doctor
Your system is ready to brew
$ brew install mono
$ brew install git
Download and install Visual Studio or JetBrains Rider
The required .net frameworks should download/install with your IDE of choice.
No extra setup necessary
Visual Studio needs a little extra configuration. Install these extensions;
- xUnit.NET 2
- SpecFlow
Requirements
- PowerShell 3
- PowerShell must be enabled for User account
$ set-executionpolicy unrestricted -s cu
Install:
$ iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
$ scoop install git
$ git clone https://github.com/jukafah/csharp-specflow-selenium.git
As of writing this guide, generating the code-behind feature.cs
files requires invoking the generator separately.
Ken Bonny wrote a couple good articles for generating those and how to configure it with File Watcher. The guide will
also walk you through associating the files together.
Generating SpecFlow Files in Rider
Restore dependencies
$ nuget restore
From solution directory
$ mono "packages/SpecFlow.2.4.1/tools/specflow.exe" GenerateAll -p SpecFlow.Selenium/SpecFlow.Selenium.csproj
Import the generated feature.cs
files to the same directory as your features.
Tests will now show in the Unit Tests / Test Explorer.
TODO
You can run them in the Unit Test explorer of your chosen IDE or via command line
Build
$ msbuild
Run tests
$ mono "packages/xunit.runner.console.2.4.1/tools/net452/xunit.console.exe" SpecFlow.Selenium/bin/Debug/SpecFlow.Selenium.dll -xml ./TestResults/xunit.xml
Selection of browser is through an environment variable. Defaults to Chrome if unprovided.
$ BROWSER=firefox mono "packages/xunit.runner.console.2.4.1/tools/net452/xunit.console.exe" SpecFlow.Selenium/bin/Debug/SpecFlow.Selenium.dll -xml ./TestResults/xunit.xml
Then you can generate a nice html report via Pickles
$ mono "packages/Pickles.CommandLine.2.20.1/tools/pickles.exe" --feature-directory=SpecFlow.Selenium/Features/ --output-directory=./TestResults/pickles --link-results-file=./TestResults/xunit.xml --documentation-format=dhtml --test-results-format=xunit2