Writing 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.Then below window pops up. In this window, you can select which step definitions you want to generate. You can also provide the name of step definition class.Here is the sample step definition class file.
 
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!!