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 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.
<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#.
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
And name it “Navigation”. This file will specify all the business navigation rules over your website.
Add the following content:
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
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
Now we are able to “web-drive” our browser with an easy API:
- 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.
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!