Here are brief steps on how to get started with SpecFlow and Selenium. This scenario assumes an ASP.NET MVC web application as the "code" and NUnit as the "test project".
- Create new MVC web application
- Create a code library project.
- Add reference to NUnit framework.
- Download Selenium IDE for Firefox. This component is used for generating tests by scripting user behavior.
- Download Selenium DotNet package. Add reference to this package into the Test project.
- Run Selenium IDE in Firefox and script your test with the web application.
- Export the generated test into a C# file.
- Add this file to the Test project.
- Download Selenium Server and run with something like
java -jar selenium-server-standalone-2.0rc3.jar
This will start Selenium server on port 4444 by default. You can configure which browser you want the Selenium to start but by default this is Firefox.
- Download and install SpecFlow. It will add new Items to the File->New menu in Visual Studio. The most important one is SpecFlow Feature item.
- If you install SpecFlow NuGet package, it will add the minimum required settings to the app.config in the Test project. Apparently this is not required if the test runner is NUnit. Contents of the app.config look like this:
<?xml version="1.0" encoding="utf-8"?>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
<!-- For additional details on SpecFlow configuration options see https://github.com/techtalk/SpecFlow/wiki/Configuration -->
<language feature="en-US" tool="" />
<unitTestProvider name="NUnit" />
<generator allowDebugGeneratedFiles="false" />
- Add reference to SpecFlow. This will be automatically added if you install NuGet package.
- Create your first SpecFlow Feature, edit the content to set up your feature and scenario(s).
- Run the test on the Test project. Copy the code from the error message into a new file in StepDefinitions directory.