Simple Test Automation using Specflow

It’s a rainy Sunday afternoon and while the boys are playing online games, I thought of writing a simple automated test using Specflow on User Login. I recorded it too and it’s in youtube, so if you want what you see, please continue reading this and check how it is done.

Here is the video uploaded in youtube : Specflow Automated Login Test

If you’re good to proceed, here are the steps :

1.Download Visual Studio. I’m using Community Edition 2015.

2. Once done, open VS and create a new project, name it BasicBDDProject.

3. Install Specflow, NUnit, NUnit Test Adapter, Selenium Webdriver, Selenium Chrome webdriver.

Right-click on project
Right-click on the Project then click on the Manage Nuget Packages…
Install Specflow
On the browse tab, search for Specflow then click on install.  Same will be done with NUnit, NUnit Test Adapter, Selenium Webdriver, Selenium Chrome Webdriver.

4. After the references were downloaded, create a feature file by right-clicking on the project, add an item then select the Specflow Feature File. Name the file as Login. Change the default feature and scenario to the following.

Feature : Login
In order to add a blog post
As a registered member
I want to be able to login with the correct credentials

Scenario : Login with correct credentials

Given I navigate to the test site
When I enter my username and password
And I login
Then I will be able to see my profile page

Notice how the Scenario texts are in different color. This is because there are no defined steps yet.
5. To define the steps, right click on the scenario and click on the generate steps.

Generate steps
Generate steps

6. When you generate the steps, a new class file is also created and named “LoginSteps.cs” and will look like the image below.

LoginSteps.cs
LoginSteps.cs

Tags:

4 thoughts on “Simple Test Automation using Specflow

Leave a Reply

Your email address will not be published. Required fields are marked *