Skip to main content

Demo Project (Specflow Setup)



Installation and Setup Steps-->

    1.Install SpecFlow for Visual Studio (Open Extensions and Updates)

2. Install SpecFlow NuGet Packages



    3. Add Feature File



   My Demo Project

   Here, I have worked on following story
   Story: Discounts on online shopping cart price for loyalty card customers
   In order to increase the reward for loyal customers
   I want to add 5-10% discounts on the final shopping cart price.
   Scenario 1: 5% discount for loyalty card customer
   Given a loyalty card customer in online checkout page
   When the shopping card total is less than $100
   Then 5% discount should be applied to the final shopping cart price.

   Create Scenarios
   In the feature file, I described what the feature needs to do Every scenario represents a different           test or use case of the feature.


   Generate Bindings
 When the steps are displayed in purple, this means that we are not ready.  To be able to execute the     scenario you need to define the bindings for each step. We need to create step definitions that bind   the statements in the test scenario to the application code. Once you click insider the specification   file and open the context menu, you will find the 'Generate Step Definitions' item.




     The following file will be generated.



   Populate Binding Methods

   Here is how the binding class will look like.
 namespace SpecflowDemo
{
    [Binding]
    public class TestDiscountSteps
    {
        decimal discountedPrice = 0;

        [Given(@"a loyalty card customer in online checkout page")]
        public void GivenALoyaltyCardCustomerInOnlineCheckoutPage()
        {

        }

        [When(@"the shopping card total is less than \$(.*)")]
        public void WhenTheShoppingCardTotalIsLessThan(int p0)
        {
            ShoppingCartDiscountCalculator cartDiscountCalculator = new ShoppingCartDiscountCalculator();
            discountedPrice = cartDiscountCalculator.GetPriceforLoyalCustomer(LoyalityCardType.Gold, 500);


        }

        [Then(@"(.*)% discount should be applied to the final shopping cart price\.")]
        public void ThenDiscountShouldBeAppliedToTheFinalShoppingCartPrice_(int p0)
        {
            Assert.AreEqual(450, discountedPrice);
        }
    }
}



 Execute SpecFlow Tests

 Once we build the project, our test/scenario will show up in the tests explorer.


Test Outcome

The generated output from the test execution is nice. You can observe each executed step and its execution time.




















Comments

Popular posts from this blog

JIRA OverView

What is JIRA? JIRA is a project management tool used for issues and bugs tracking system for all types of testing.The JIRA dashboard consists of many useful functions and features which make handling of issues easy. The following points explain some interesting details of JIRA. • JIRA is an incident management tool. • JIRA is not an acronym, the name 'JIRA' comes from the Japanese word 'Gojira' • JIRA is developed by Australian Company Atlassian • JIRA is a platform independent tool; it can be used with any OS. • JIRA is multi-lingual tool − English, French, German, Japanese, Spanish, etc. • JIRA can be integrated with many other tools like GitHub, Team Foundation Software and many more. • JIRA is a commercial tool and available as a Trial version for a limited time. • To utilize JIRA services, a license is required. Features: JIRA is one the best product management tool which includes: Issue tracking & management: A software application that allows to