Click here to Skip to main content
13,633,761 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


7 bookmarked
Posted 28 May 2014
Licenced CPOL

How-to: End to End Automated Testing with Specflow

, 28 May 2014
Rate this:
Please Sign up or sign in to vote.
End to end automated testing with Specflow

End-to-End testing is about testing a full “slice” of an IS, from user input to tiers (DB, service provider) and back to the system output.

For this concern, at Betclic, we use 2 tools:

Quick Behavior Driven Design Glossary

Spec (specification)
Description of how an information system should behave
Part of an Information System, that has its own behavior
Part of a feature
Atomic operation of a scenario


Visual Studio Extensions
Fisrt of all, install the Specflow VS extension.

specflow extension

Specflow extension for VS 2013
Nuget Packages
In your target test project, add the following packages:
  • PM> Install-Package SpecFlow
  • PM> Install-Package Selenium.WebDriver
  • PM> Install-Package NFluent
By default, Specflow uses NUnit. As the recommended test framework is MSTest, you have to tune the concerned config section.
    <!-- For additional details on SpecFlow configuration
         options see -->
    <unitTestProvider name="MsTest" />
Files Organisation
At the of the Test project, add a “Specs” and a “Steps” folders.The first one will hold the Gherkin files, the second one will contain the associated transcription of spec into C#.

First test


Let us say we want to test the navigation of our menu bar.
In a default MVC Website, I added a new “StaticContent” controller, and added a link to it in the layout’s menu.
We want to check if a click on this link browses to the target page.


First, we create a “specification” in Gherkin langage.

Right-click on the Specs folder and add a new SpecFlow Feature file:

Add a Feature File

Add a Feature File

And name it “Navigation”. This file will specify all the business navigation rules over your website.
Add the following content:

Feature: Navigation 	In order to browse the site 	As an user 	I want to use the naviagtion bar Scenario: Browse to StaticContent page 	Given I am on the home page 	When I click on StaticContent link in navigation bar 	Then I should land on StaticContent page

A feature and its first scenario

Pretty self-describing, isn’t it? The main advantage of the Gherkin language is that everybody, from Business to QA people have the same understanding of it.
By sharing a common language, we are able to efficiently communicate, and build a system that purely reflects the business needs. Even better, you can build those specifications with the business and QA.

Translate to Steps

By right-clicking in the feature file and selecting “Generate Step definition”, you will launch a wizard tool that will create the step file skeleton.

Target the “Steps” folder before generating the steps. ;-)

You should have a new test file with 3 blocks:

Default step file skeleton

Default step file skeleton

Our scenario implies the use of a browser. Here comes WebDriver, that allows us to abstract the communication with the browser.

For this, we start by sharing the same instance of browser execution between the different steps of our secnario:

Browser initialize and tear down

Browser initialize and tear down

Now we are able to “web-drive” our browser with an easy API:

Steps implementation

Steps implementation
It’s a simple transcription of the scenario:
Given: Initial state, load the default page of the website
When: Description of an action, here, the click on the StaticContent page’s link
Then: the expected state: i.e., do we have browse to the StaticContent page ?

Run the test: a “web-driven” Firefox window will be launched by WebDriver/Selenium, and perform few actions.

Test explorer result window

Test succeded!


In this article, we saw how to setup a functional environment for starting Behavior Driven Design on web application.

To achieve this, we rely on the pair Specflow / WebDriver.

More to come about WebDriver API, stay tuned!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Betclic Tech
Chief Technology Officer Betclic
France France
This member doesn't quite have enough reputation to be able to display their biography and homepage.
Group type: Organisation

3 members

You may also be interested in...


Comments and Discussions

QuestionSpecRun and outline scenario Pin
Member 1271127730-Aug-16 5:12
memberMember 1271127730-Aug-16 5:12 
QuestionAbout Selenium with MVC and IIS Pin
deelll26-Mar-16 7:15
memberdeelll26-Mar-16 7:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180712.1 | Last Updated 29 May 2014
Article Copyright 2014 by Betclic Tech
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid