Specflow Tutorial
Introduction to SpecFlow Installation of SpecFlowWriting first SpecFlow test in Visual Studio Writing step definitions for a SpecFlow feature file Executing SpecFlow scenarios and feature files Using SpecFlow runner to execute the feature files Using tags in SpecFlow Passing parameters to steps Data table in SpecFlow Scenario Background Scenario outline Hooks in SpecFlow Executing Selenium tests with SpecFlow Executing the failed test multiple times Sharing selenium Webdriver instance in SpecFlow Writing to SpecFlow HTML reportsWriting step definitions in Specflow
Now let us see how to write the step definitions for a feature file in SpecFlow. Just right click on the feature file and then select “Generate Step Definitions” option as shown in below image.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using TechTalk.SpecFlow;
namespace Specflow
{
[Binding]
public class SimpleFeatureFileSteps
{
double balance;
[Given(@"I have $(.*) in my account")]
public void GivenIHaveInMyAccount(int initialBalance)
{
balance = initialBalance;
}
[When(@"I withdraw $(.*) from ATM")]
public void WhenIWithdrawFromATM(int withdrawAmt)
{
balance -= withdrawAmt;
}
[Then(@"my balance should be $(.*)")]
public void ThenMyBalanceShouldBe(int remaining)
{
Assert.IsTrue(balance == remaining,"Balance Verification");
}
}
}
Web development and Automation testing
solutions delivered!!